设置小数位数(最多3个小数位) [英] seting up decimal number up to 3 decimal place

查看:127
本文介绍了设置小数位数(最多3个小数位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置小数点后最多3个小数位.

how can i set the decimal value up to 3 decimal place.

推荐答案

出于计算目的:
->无论您拥有多少,都应乘以1000
->然后使用Truncate
->然后除以1000.
参考: MSDN:Math.Truncate方法(双精度) [
For calculation purpose:
-> Whatever number you have, multiply it by 1000
-> then use Truncate
-> then divide by 1000.
Refer: MSDN: Math.Truncate Method (Double)[^]


If just for display purpose, you can try:
double sample = 12.34567;
Console.Out.WriteLine(sample.ToString("#.000"));


函数Truncate似乎与
类似
Math.Floor(Number)

除了小号也适用于负数:
http://stackoverflow.com/questions/14/difference-在网络之间进行数学截断 [ http://msdn.microsoft.com/en-us/library/kfsatb94.aspx [ ^ ]

这样就剩下一个供您选择了:)
The function Truncate seems to be simular to

Math.Floor(Number)

except truncets works for negative numbers as well:
http://stackoverflow.com/questions/14/difference-between-math-floor-and-math-truncate-in-net[^]

As for display purposes there are quite a number of different formats:
http://msdn.microsoft.com/en-us/library/kfsatb94.aspx[^]

So there is just left for you to pick one:)


这篇关于设置小数位数(最多3个小数位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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