如何在不使用数字 % 10 的情况下使用 java 找到数字整数的最右边数字?看说明 [英] How do i find the right most digit of a number integer with java without using number % 10? see the description
本文介绍了如何在不使用数字 % 10 的情况下使用 java 找到数字整数的最右边数字?看说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在我正在使用这样的东西:基本上该程序应该将 X(# 的最右边数字)打印到 X 个小数位,例如:
Right now I'm using something like this: Basically the program is supposed to print X (right most digit of a #) to X decimal places for example:
- 输入 3.56,应显示 0000000000000003.560
- 输入 56.7 应显示:000000000056.700000
- 输入 1002.5 应显示 00000000000001002.50
但是数字% 10
,现在条件只接受数字没有小数,所以如果我输入程序就会关闭带小数的数字我只需要一个数字 % 10
的替代.
but number % 10
,condition right now only accepts number
w/o decimals, so the program closes if i enter
a number with decimals
I only need an alternative for number % 10
.
double number;
if (number % 10 == 1)
System.out.printf("%020.1f\n",number);
推荐答案
看来你正在寻找类似的东西
It seems that you are looking for something like
System.out.printf("%020." + ((int) number) % 10 + "f\n", number);
((int) number)
将去掉分数56.7
-> 56
,所以现在你可以安全地使用%10
获取最后一位数字.
((int) number)
will get rid of fraction making 56.7
-> 56
, so now you can safely use %10
to get last digit.
这篇关于如何在不使用数字 % 10 的情况下使用 java 找到数字整数的最右边数字?看说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文