Float.toString()和Integer.toString()如何工作? [英] how does Float.toString() and Integer.toString() works?
本文介绍了Float.toString()和Integer.toString()如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何实现将float或int转换为字符串的算法? 我找到一个链接 http://geeksforgeeks.org/forum/topic/amazon-interview-question-for-software-engineerdeveloper-0-2-years-about-algorithms-13
How can i implement an algorithm to convert float or int to string? I found one link http://geeksforgeeks.org/forum/topic/amazon-interview-question-for-software-engineerdeveloper-0-2-years-about-algorithms-13
但是我不明白那里给出的算法
but i cant understand the algorithm given there
推荐答案
在大多数字符编码中,数字0-9是顺序的,因此在其整数值之间进行旋转将有助于解决问题:
the numbers 0-9 are sequential in most character encoding so twiddling with the integral value of it will help here:
int val;
String str="";
while(val>0){
str = ('0'+(val%10)) + str;
val /= 10;
}
这篇关于Float.toString()和Integer.toString()如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文