Java - 如何从整数(Money)中获取double

eMi*_*eMi 2 java algorithm currency

我有:

int number = 1255; -> //It could also be 125(1€25Cent) or 10(10Cent) or 5(5Cent)

public double toMoney(int number)
{
...
}
Run Code Online (Sandbox Code Playgroud)

作为回报,我想要双号:12.55或如果输入:10然后:00.10

我知道我可以用Modulo这样做:

1255%100 ..得到55 ..但如何做到12和最后,如何形成一个双倍?

Mic*_*rdt 5

该方法不应该存在,因为它无法给出正确的结果.

因为在内部,double是不能准确地表示相同的0.1,0.2或0.3的数的格式(二进制浮点)在所有.阅读浮点指南以获取更多信息.

如果需要小数,则输出格式应为BigDecimalString.