当我尝试打印时info(numeralsToTxt(3492.4069)); ,它给我输出为*** Three Thousand Four Hundred Ninety Two and 41/100. 现在我希望它是*** Three Thousand Four Hundred Ninety Two and 406/1000 当我检查方法 numericsToTxt() 我发现函数frac()返回 .41
请帮忙。
当我尝试打印时info(numeralsToTxt(3492.4069)); ,它给我输出为*** Three Thousand Four Hundred Ninety Two and 41/100. 现在我希望它是*** Three Thousand Four Hundred Ninety Two and 406/1000 当我检查方法 numericsToTxt() 我发现函数frac()返回 .41
请帮忙。
frac()不返回 .41。它decRound(frac(_num), 2)是返回 0.41。decRound 方法的第二个参数是您想要的小数位数。
你能做的就是改变
int numOfPennies = (decRound(frac(_num), 2) * 100) mod 100;
到
int numOfPennies = (decRound(frac(_num), 3) * 1000) mod 1000;
然后,将方法底部的输出字符串更改numeralsToTxt为显示'/1000'而不是'/100'
实际输出将是 407/1000,而不是 406/1000,因为它会四舍五入。