设置双格式,带2位小数

编程入门 行业动态 更新时间:2024-10-23 23:31:04
本文介绍了设置双格式,带2位小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个简短的等式:

double compute,computed2; compute=getminutes/60;

其中 getminutes 是 int 我想设置相当于 compute 的2位小数。 0.00 如何格式化等效的2个小数位?

where getminutes is int and I want to set the equivalent of compute with 2 decimal places. 0.00 how can I format the equivalent with 2 decimal places?

示例:

compute=45/60 it should be 0.75

这是我的工作:

DecimalFormat df2 = new DecimalFormat("00.00000"); double computed,computed2 = 00.000; computed=60/getitbyminutes; df2.format(computed); computed2=computed-8; df2.format(computed2); System.out.printf("%1$.2f",computed); System.out.println(); System.out.printf("%1$.2f",computed2);

输出结果如下:

1.00 7.00

推荐答案

将其转换为Double

Cast it to Double

compute=(Double)getminutes/60;

然后使用Peter提到的 DecimalFormat 。

and then use DecimalFormat as mentioned by Peter.

更多推荐

设置双格式,带2位小数

本文发布于:2023-11-10 06:18:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574585.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:小数   格式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!