For Newbie

Thursday, 1 January 2015

How to rounding fractional numbers in the hundreds to thousands of Delphi


em, this time a few tips on how to round fractional numbers in the hundreds to thousands. for example, Rounded to 192 000 192 333 Rounded to 174 000 174 250 if you have any questions, why too should be rounded? whereas the figure is not a number or a decimal fraction. OK, rounding like this would be necessary for the calculation of financial data with the reach of large numbers. for example, when we talk about the payment of an installment, is not very rare when there are hundreds of dollars installments with fractions? especially if the number reached millions of dollars. :)

this case I had just experienced when I create a financial system. from whence also my intention to share here because it has not much to write about this. either because this is too trivial to be missed or how I do not know. but, well, may be useful.:)
way of rounding off is quite simple. algorithm that I use is to divide it by the number 1000, then multiply it again with number 1000. so, for the code themselves something like this:
number: = (digit span 1000) * 1000;
where number is the number of type integer. if a real number or a float, then added trunc () would roughly like this for a number that is a real number or a float:
number: = (trunc (number) div 1000) * 1000;
thus, may help.

Share on Facebook
Share on Twitter
Share on Google+

Related : How to rounding fractional numbers in the hundreds to thousands of Delphi