B bluedude Well-Known Member Licensed User Longtime User Oct 9, 2014 #1 Hi, I need to round my doubles like: 1.488 = 1.40 It should be working like the Excel trunc function which does that. Any suggestions?
Hi, I need to round my doubles like: 1.488 = 1.40 It should be working like the Excel trunc function which does that. Any suggestions?
DonManfred Expert Licensed User Longtime User Oct 9, 2014 #2 1.488 to 1.4 is not round(x,1)... I think you should use Numberformat in this case. Upvote 0
derez Expert Licensed User Longtime User Oct 9, 2014 #3 B4X: Dim n As Double = 1.488 Dim m As Double = Floor(n*10)/10 This returns 1.4 , I don't know how to force the 0 to appear after the 4. Upvote 0
B4X: Dim n As Double = 1.488 Dim m As Double = Floor(n*10)/10 This returns 1.4 , I don't know how to force the 0 to appear after the 4.
ac9ts Active Member Licensed User Longtime User Oct 9, 2014 #4 If you are keeping 1.4 as a double, the math routines will treat it as 1.4 no matter how many 0's are at the end of if. If you are printing/displaying 1.4 as a string, try just a simple string append: B4X: Dim n As Double = 1.488 Dim m As Double = Floor(n*10)/10 Dim s As String = m & "0" BTW, In Excel 2007, TRUNC(1.488,1) returns 1.4 Upvote 0
If you are keeping 1.4 as a double, the math routines will treat it as 1.4 no matter how many 0's are at the end of if. If you are printing/displaying 1.4 as a string, try just a simple string append: B4X: Dim n As Double = 1.488 Dim m As Double = Floor(n*10)/10 Dim s As String = m & "0" BTW, In Excel 2007, TRUNC(1.488,1) returns 1.4
B bluedude Well-Known Member Licensed User Longtime User Oct 9, 2014 #5 Hi, I solved it with floor. Thanks anyway! Upvote 0