Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Report Design
Message Icon Topic: Looking for Number After Decimal Post Reply Post New Topic
Author Message
jsh8286
Groupie
Groupie
Avatar

Joined: 09 Mar 2012
Online Status: Offline
Posts: 45
Quote jsh8286 Replybullet Topic: Looking for Number After Decimal
    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.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4362
Quote lockwelle Replybullet 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
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.