PDA

View Full Version : [SOLVED:] Truncate number to two decimal places without rounding



jonsonbero
03-10-2022, 02:19 PM
Hello everyone
I have this line of code for rounding decimal places

End Select
Basic = Application.WorksheetFunction.Round(X, 2)
End Function



I only need 2 decimal places after the decimal. without rounding ... I tried using the TRUNC function but without success


I would appreciate this help if possible.

Paul_Hossler
03-10-2022, 03:05 PM
?int(100*12345.6789)/100

12345.67

jonsonbero
03-10-2022, 05:15 PM
Thanks a lot Mr. Paul_Hossler
I appreciate you taking the time to answer my question.
but I am having major difficulty figuring out the correct syntax for that line.
Basic = Application.WorksheetFunction.Round(X, 2)


please help me with that ... Thanks again

macropod
03-10-2022, 07:02 PM
Thanks a lot Mr. Paul_Hossler
I appreciate you taking the time to answer my question.
but I am having major difficulty figuring out the correct syntax for that line.
Basic = Application.WorksheetFunction.Round(X, 2)
It's not a WorksheetFunction - it's straight VBA!

Basic = INT(X * 100)/100

Paul_Hossler
03-11-2022, 04:29 AM
Sorry, you have some VBA statements, so I just did the algorithm so that you could update your code

Probably something like this





End Select
Basic = Int(100*X)/100 End Function

snb
03-11-2022, 05:00 AM
=TEXT(A1;"0,00")
or

=TEXT(A1,"0.00")
or

format([A1],"0.00")

jonsonbero
03-11-2022, 07:13 AM
thanks for everyone