Print Page | Close Window

Looking for Number After Decimal

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=22987
Printed Date: 02 May 2024 at 11:54am


Topic: Looking for Number After Decimal
Posted By: jsh8286
Subject: Looking for Number After Decimal
Date Posted: 18 Nov 2021 at 8:14am
We have a field called "Base Price" which in our table is always 4 numbers after the decimal. We want to be able to read the number right after the decimal and based on this reading return either two decimals for the price or 4 decimals.

For example we want to know if the digit right after the decimal is a "0" or not. If it is a "0" then we leave the field alone. So in this case if the field reads "0.0925" we return "0.0925".

If the field reads "1" or any other number up to "9" i.e. not a zero obviously then we want to return only two decimals and also round up the number as well. So for example if the field reads "0.1099" we want to return in this case "0.11".

Simply if it is a "0" immediately to the right of the decimal stays as four digits to the right of the decimal. If 1-9 then round up (if applicable) to only two digits.

Thanks in advance for postings.



Replies:
Posted By: lockwelle
Date Posted: 18 Nov 2021 at 8:37am
The first thing that pops into my head is:

if Remainder({table.field} * 10, 10) = 0 then
leave the decimal
else
round the decimal

I am simply multiplying by 10 and looking at the remainder. If this doesn't work because there are still decimals, add INT(Remainder(...))

HTH



Print Page | Close Window