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
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
相关文章推荐
- find all pairs of elements in a balanced BST that sum to a certain number
- Server-02 To view the connection number of shared folder in windows OS
- Number of Facebook Friends Linked To Anxiety 53
- [LeetCode] Number of Lines To Write String 写字符串需要的行数
- The power of recursion: Number-to-Text conversion
- Given an array of ages (integers) sorted lowest to highest, output the number of occurrences for eac
- 452. Minimum Number of Arrows to Burst Balloons
- 452. Minimum Number of Arrows to Burst Balloons
- BigDecimal(-)Difference of BigDecimal toString() method between JDK1.4 and above version
- the travel of solving iframe navigate to display page of certain part of parent html page
- Write an Efficient Method to Check if a Number is Multiple of 3
- [Leetcode] 452. Minimum Number of Arrows to Burst Balloons 解题报告
- 【LeetCode】452. Minimum Number of Arrows to Burst Balloons
- -[NSDecimalNumber rangeOfCharacterFromSet:]: unrecognized selector sent to instance
- Leetcode-452. Minimum Number of Arrows to Burst Balloons
- 【LeetCode】 452. Minimum Number of Arrows to Burst Balloons
- Your task is to find for a given phone number any of its divisions into groups of two or three digit
- Minimum Number of Arrows to Burst Balloons_Week8
- 452. Minimum Number of Arrows to Burst Balloons| Leetcode Greedy
- The minimum number of elements to reach the end of an array