Delphi: Round a number to thousands place (12345678 to 12345000)
Question by Mahdi | 2014-02-20 at 10:35
Hi. I'd like to round this number (12345678) to (12345000) in Delphi.
How can i do that? I search a lot but I didn't find anything. Also I don't know how to use (GetRoundMode).
Thanks :)
Related Topics
Delphi/Lazarus: 3 Ways to round a Number to X Decimal Places
Tutorial | 7 Comments
Delphi/Lazarus: Function to Round Number to any Position after or before Decimal Point
Tutorial | 0 Comments
PHP: Rounding Numbers
Tutorial | 0 Comments
Delphi/Lazarus: Round Decimal Numbers up, down and normally
Tip | 0 Comments
Delphi/Lazarus: Round Number to the next 10, 100 or 1000
Question | 1 Answer
List of all World Cup Champions and Winners of the first four Places
Info | 0 Comments
Delphi/Lazarus: Only allow Numbers in TEdit
Tip | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
This cannot be done with the typical Delphi round() function like you can do it when rounding in PHP using a negative precision.
Just try the following code instead:
If you always want to round down like in your example, you can use the function floor or trunc instead of round:
Because you brought me to that idea, I have just written a small function to round a number to any decimal place in Delphi. In this function you can use positive or negative values as a second parameter in order to round to a position after or before the decimal point.
2014-02-21 at 01:42
Perhaps, also the build in function RoundTo from the unit Math can help you:
Or with setting the Round Mode:
SetRoundMode accepts the following parameters:
To prevent the function from rounding up, you can just use the rmTruncate mode.
2014-02-21 at 02:58