nibbo Active Member Licensed User Longtime User Oct 15, 2015 #1 Simple I am sure but I can't find it in the documentation. How do I round down to 2 decimal places?
wonder Expert Licensed User Longtime User Oct 15, 2015 #3 sorex said: use floor() Click to expand... Floor indeed, but it truncates the decimal places. Here's the code snippet that you need: Code: Copy Sub RoundDown(number As Double, decimalPlaces As Int) As Double Return Floor(number * Power(10, decimalPlaces)) / Power(10, decimalPlaces) End Sub Corrected version, thanks Sorex. Code: Copy Log(RoundDown(24.1499999)) 'Output: 24.14 Last edited: Oct 15, 2015 Upvote 0
sorex said: use floor() Click to expand... Floor indeed, but it truncates the decimal places. Here's the code snippet that you need: Code: Copy Sub RoundDown(number As Double, decimalPlaces As Int) As Double Return Floor(number * Power(10, decimalPlaces)) / Power(10, decimalPlaces) End Sub Corrected version, thanks Sorex. Code: Copy Log(RoundDown(24.1499999)) 'Output: 24.14
S sorex Expert Licensed User Longtime User Oct 15, 2015 #4 wonder said: Floor indeed, but it truncates the decimal places. Click to expand... yeah, I corrected it immediatly after my post tho Upvote 0
wonder said: Floor indeed, but it truncates the decimal places. Click to expand... yeah, I corrected it immediatly after my post tho
S sorex Expert Licensed User Longtime User Oct 15, 2015 #5 but it rounds up so it ain't good for him Upvote 0
wonder Expert Licensed User Longtime User Oct 15, 2015 #6 sorex said: yeah, I corrected it immediatly after my post tho Click to expand... Ahh, I see you corrected it. Round2 will however always round up. 24.1499 will become 24.15. Upvote 0
sorex said: yeah, I corrected it immediatly after my post tho Click to expand... Ahh, I see you corrected it. Round2 will however always round up. 24.1499 will become 24.15.
S sorex Expert Licensed User Longtime User Oct 15, 2015 #7 Code: Copy Dim i As Double i=2.34999 Log( Floor(i*100)/100 ) not sure if it's safe for all values tho Upvote 0
Code: Copy Dim i As Double i=2.34999 Log( Floor(i*100)/100 ) not sure if it's safe for all values tho
S sorex Expert Licensed User Longtime User Oct 15, 2015 #8 by the way do you sometimes need to look for your cursor with that theme? I use it too at home and sometimes the cursor is kind of lost in the background. Upvote 0
by the way do you sometimes need to look for your cursor with that theme? I use it too at home and sometimes the cursor is kind of lost in the background.
wonder Expert Licensed User Longtime User Oct 15, 2015 #9 sorex said: Code: Copy Dim i As Double i=2.34999 Log( Floor(i*100)/100 ) not sure if it's safe for all values tho Click to expand... Ahaha good job!! I think I like math a little bit too much! You solution is way simpler than mine! EDIT: No... No issues with the cursor. Last edited: Oct 15, 2015 Upvote 0
sorex said: Code: Copy Dim i As Double i=2.34999 Log( Floor(i*100)/100 ) not sure if it's safe for all values tho Click to expand... Ahaha good job!! I think I like math a little bit too much! You solution is way simpler than mine! EDIT: No... No issues with the cursor.
nibbo Active Member Licensed User Longtime User Oct 15, 2015 #10 Thanks all, yes I found Floor truncates the decimals and returns an integer even though the when you type Floor it implies it will return a double. As stated above Round2 always rounds up. I will write a little function using the Floor(double * 100) / 100 which seems the neatest. Thanks all. Upvote 0
Thanks all, yes I found Floor truncates the decimals and returns an integer even though the when you type Floor it implies it will return a double. As stated above Round2 always rounds up. I will write a little function using the Floor(double * 100) / 100 which seems the neatest. Thanks all.