将数字转换为带小数的单词(java)

将数字转换为带小数的单词(java),java,Java,我想把数字转换成单词,经过一些研究,我可以成功地把数字转换成英语单词。但是,这只适用于整数。我想将带小数的数字转换为英语单词,例如: 123.45->一百二十三和四十五美分 有什么解决办法吗 参考资料:由于您拥有所有的基本功能,我将仅提供一个伪代码建议,以获得下半部分: get the cents-only portion as a double. (0.45) multiply the cents by 100. (45) use your normal conversion techniqu

我想把数字转换成单词,经过一些研究,我可以成功地把数字转换成英语单词。但是,这只适用于整数。我想将带小数的数字转换为英语单词,例如:

123.45->一百二十三和四十五美分

有什么解决办法吗


参考资料:

由于您拥有所有的基本功能,我将仅提供一个伪代码建议,以获得下半部分:

get the cents-only portion as a double. (0.45)
multiply the cents by 100. (45)
use your normal conversion technique to the English words. (Forty Five)
编辑如何将仅美分的部分作为双精度

    double money = 123.45;

    int dollars = (int) Math.floor(money);
    double cents = money - dollars;
    int centsAsInt = (int) (100 * cents);

    System.out.println("dollars: " + dollars);
    System.out.println("cents: " + cents);
    System.out.println("centsAsInt: " + centsAsInt);
使用大小数。您可以按如下方式获得分数部分:

final BigDecimal intPart = new BigDecimal(orig.toBigInteger);
final BigDecimal fracPart = orig.minus(intPart);
final int scale = fractPart.scale();
final String fractPartAsString = fracPart.mult(BigDecimal.TEN.pow(scale));
// treat fractPartAsString

嗯,你已经完成了大部分工作!这不应该是保险的,是吗?到目前为止,你做了什么来解决这个问题。。。请将其添加到您的问题中。。。不要把作业放在这里。。这是stackoverflow.com而不是google…@Cross-Bone,我只是说把你的代码放进去,这样我们就可以帮助你,仅仅根据你的问题,我们帮不了你~