您的位置:首页 > 大数据 > 人工智能

Truncate a number to a certain number of decimal places

2009-11-05 15:39 447 查看
How do you truncate a number to a certain number of decimal places? for example, if i have 1.149 and i want to truncate that to 2 decimal places, the number should be 1.14. math.truncate() changes the number to 1.

Answer:

multiply the number by 10 raised to the power of the number of desired decimal points, use math.truncate() and divide by the original power of 10.

1.149 * (10^2): 114.9
math.truncate(): 114
114 / (10^2): 1.14

ASP.NET Example:

Math.Truncate(Convert.ToDecimal(Eval("AMOUNT")) * 100) /100
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: