|
|||||||||
|
|
![]() |
|
|
|
![]() |
![]() |
|
Crystal Reports Tools: Improve Performance While Saving Time and Money |
|
Crystal Reports: RoundingWhen you display a number in a Crystal Report, you have the option to round the number. Crystal Reports does only traditional rounding where values 0.5 and above are rounded up to the nearest value, and values below 0.5 are rounded down. But there are other ways to do rounding and they may cause your report to display values that don’t match other systems or applications. Some programming languages use "Bankers rounding," which was developed as a more accurate method of rounding. With Bankers rounding, values below 0.5 go down and values above 0.5 go up. Values of exactly 0.5 go to the nearest even number. So 12.5 will be rounded down to 12 (as in the example on the right) and a value of 13.5 will be rounded up to 14. The justification for bankers rounding is apparent when you imagine a list with a typical distribution of even and odd numbers. Such a list may show the numbers 12.0 to 13.0 in steps of 0.1. There are 9 values that need to be rounded. Traditional rounding moves 5 of the 9 values up and 4 down–always. This is biased (1/9 more up than down). By moving 0.5 to the nearest even number it is now exactly 9 of the 18 numbers in each direction. It might not sound like much, but if it relates to interest calculations on billions of dollars, the difference in rounding calculations is still worth many millions of dollars. Round a number upSometimes in a report, you would like to round a number up if it has any decimal places at all (not just 0.5 or over). You can do this with a formula of:
If the decimals are 0 then use the original number as it has no decimals. Otherwise add one to the truncated value and you have rounded the number with decimals up to the next integer value. Thanks to Mike (mbarron) on Tek-Tips for answering this question.
ToWords will round value upThe ToWords function will round the number prior to converting it to words. If you are trying to print cheques then you need to truncate the number prior to converting to words. The complete formula to convert the amount to words in dollars and cents is
Another formula for rounding upIf you are rounding up with the Int function, consider an efficient method provided by Lisa on Tek-Tip).
So while: Int(5.6) has a
result of 5, The logic in the above formula is This technique works only on positive numbers, but sometimes that is all we need.
This article is copyrighted by Crystalkeen, Mindconnection, and Chelsea Technologies Ltd. It may be freely copied and distributed as long as the original copyright is displayed and no modifications are made to this material. Extracts are permitted. The names Crystal Reports and Seagate Info are trademarks owned by Business Objects. |
|
|