Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Report Design
Message Icon Topic: Truncate issue Post Reply Post New Topic
Author Message
andrew
Newbie
Newbie
Avatar

Joined: 11 Nov 2008
Location: United Kingdom
Online Status: Offline
Posts: 35
Quote andrew Replybullet Topic: Truncate issue
    Posted: 18 Dec 2008 at 8:42am

I've got a small formula that translates hours into (working) days...

The SQL will contain the data with decimal point... so for 80 hours it will come into crystal as '80.00'.

To remove the .00 I use a quick formula (called QTY Maths):

truncate({Time.HRS} / 8,0)

Next I work out if there are enough hours actually in the record to count a day or not, so use another formula...
 
if ({Time.HRS} > 8) Then
cStr("(" & truncate({@QTY Maths},0) & " Days)")
                          
Else
"(Under a day)"
 
--------------
 
The above formula will output '(10.00 Days)'
 
Anyone have any idea why the truncate () isnt working?
 
I was expecting it to output (10 Days)
IP IP Logged
themessenger
Groupie
Groupie
Avatar

Joined: 15 Aug 2008
Location: United Kingdom
Online Status: Offline
Posts: 48
Quote themessenger Replybullet Posted: 18 Dec 2008 at 9:33am
Why not use

ToText({QTY Maths},0,'')

to remove decimal and commas?

Regards,

TheMessenger
Managing Director
www.allmymenus.com
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3701
Quote hilfy Replybullet Posted: 18 Dec 2008 at 3:00pm
When converting a number to a string, Crystal defaults to two decimal places - whether there are decimal places in the number or not.  So, you don't necessarily need to truncate, just convert without the decimals.  To refine themessenger's answer, in Crystal syntax it would be
 
ToText({@QTY Maths}, 0)
 
You're using VB syntax (which I'm not super familiar with) but I think your formula will look something like this:
 
if ({Time.HRS} > 8) Then
"("& cStr({@QTY Maths},0) & " Days)"
Else
"(Under a day)"
 
Use the cStr around just the part that needs to be converted to a string, not around the whole thing.
 
-Dell
IP IP Logged
themessenger
Groupie
Groupie
Avatar

Joined: 15 Aug 2008
Location: United Kingdom
Online Status: Offline
Posts: 48
Quote themessenger Replybullet Posted: 18 Dec 2008 at 4:26pm
Ok - not one to contradicrt a moderator (usually) - Totext is not VB - check the help files. The code I supplied was the solution to the problem raised.
Managing Director
www.allmymenus.com
IP IP Logged
andrew
Newbie
Newbie
Avatar

Joined: 11 Nov 2008
Location: United Kingdom
Online Status: Offline
Posts: 35
Quote andrew Replybullet Posted: 19 Dec 2008 at 12:54am
Hi Guys,
 
Many thanks for your replies - it works perfectly now!
 
The code I used was:
 
"(" & ToText({@QTY Maths}, 0) & " Days)"
 
Thanks once again!
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.031 seconds.