如何在数字中加上小数 [英] how to put a decimal in a number

查看:89
本文介绍了如何在数字中加上小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一个整数计数,我想在其中加一个小数,使它看起来像美元数量计算。因此数字59将是.59而数字259将是2.59。



我尝试使用这样的十进制方法(00。##)但这只是添加在这个数字的末尾为0',59为59.00。



任何帮助都会很棒!



谢谢你

解决方案

在显示它之前我只能除以100。


你可以尝试类似:

  int 金额; 
int dollar = amount / 100 ;
int 美分=金额% 100 ;
System.out.format( 金额=%d。%d,美元,分);


Hi there,
I have a whole number counting up and I would like to put a decimal in it to make it look like a US Dollar amount counting up. so the number 59 would be .59 and the number 259 would be 2.59.

I tried using the decimal method like this (00.##) but that just adds to 0''s on the end of the number like this, 59 would be 59.00.

Any help would be awesome!

Thank you

解决方案

I''d just divide by 100 before displaying it.


You could try something like:

int amount;
int dollars = amount / 100;
int cents = amount % 100;
System.out.format("Amount = %d.%d", dollars, cents);


这篇关于如何在数字中加上小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆