如何格式化一个double类型的变量 [英] How to format a variable of double type

查看:183
本文介绍了如何格式化一个double类型的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个double类型的变量,表示值约为34.323423423123456。我想格式化为只有两位小数(例如34.32),四舍五入;例如2.229934345会变成2.23。

我是Java的新手,而且我从C#知道的技巧都没有用。

解决方案

与此相关问题使用DecimalFormat setRoundingMode


I have a variable of double type representing a value of about 34.323423423123456. I'd like to format it to have only two decimal places (e.g. 34.32), rounded properly; e.g. 2.229934345 would become 2.23.

I am new to Java and none the tricks I know from C# worked.

解决方案

Related to this Question use DecimalFormat setRoundingMode

这篇关于如何格式化一个double类型的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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