Thursday 1 January 2015
Home »
Tips and Trick Delphi
» How to rounding fractional numbers in the hundreds to thousands of Delphi
How to rounding fractional numbers in the hundreds to thousands of Delphi
To Share | Thursday 1 January 2015
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.