你怎么能得到包含在双位数? [英] How can you get the number of digits contained in a double?
问题描述
我试图让数字在下面的双重价值数:56.46855976不用将其转换为一个字符串(和单纯用,代替。)。
I'm trying to get the number of digits in the following double value: 56.46855976 without using converting it to a string (and simply replacing the "." with a "").
任何人有什么想法?
干杯
推荐答案
怎么算的时候,你必须在10,直到它小于1把数 - >,让您在小数点前面的数字
Count how often you must divide the number by 10 until it's smaller than 1 -> that gives you the digits before the decimal point.
再算上多久您必须通过10,直到它等于Math.Floor,结果乘以原来的号码 - >,让你的小数点后面的数字
Then count how often you must multiply the original number by 10 until it equals the Math.Floor-result -> that gives you the digits behind the decimal points.
添加。 。很高兴
修改:由于乔伊指出的,是它的一些uncertianity。定义数字的最大数量事先让你不创建一个无限循环。
在另一方面 - ?多久是丹麦海岸...
Edit: As Joey points out, there is some uncertianity in it. Define a maximum number of digits beforehand so you don't create an infinite loop. On the other hand - "How long is the coast of Denmark?"...
这篇关于你怎么能得到包含在双位数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!