Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Report Design
Message Icon Topic: Using ROUND and ToTEXT Post Reply Post New Topic
Author Message
bal1
Groupie
Groupie


Joined: 28 Nov 2012
Online Status: Offline
Posts: 44
Quote bal1 Replybullet Topic: Using ROUND and ToTEXT
    Posted: 13 Jun 2013 at 2:27am
Hi,

I have the following formula:

totext(Round(({@TotalFailed}/{@TotalSampleByComponent})*100,2),"0.00") + "%"

I would expect this to yield 3.63 based on the values used (11/303).
Instead I'm getting 4.00%

Not sure why - or if it has to do with the use of ToText along with the Round.

Thanks!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 13 Jun 2013 at 3:32am
totext(Round(({@TotalFailed}/{@TotalSampleByComponent})*100,2),"0.00",2) + "%"
or you can simplify as
totext(({@TotalFailed}%{@TotalSampleByComponent}),"0.00",2) +'%'
IP IP Logged
bal1
Groupie
Groupie


Joined: 28 Nov 2012
Online Status: Offline
Posts: 44
Quote bal1 Replybullet Posted: 13 Jun 2013 at 3:50am
Love the simplified version.

Can you help me understand the use of '%' and how we eliminated the use of 'Round'

Thanks so much
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 13 Jun 2013 at 3:58am

x%y is the same as ((x/y)*100) (e.g gets the percentage value of x to y)

Totext also will round. If you do not specify where to round it will round to a whole number even if you format it like you did "0.00". You would think that the format would indicate where to round but it does not. The ",2" at the end ot the totext indicates how many decimal points to use and when it applies that rule it uses standard rounding rules not truncating.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 13 Jun 2013 at 3:59am
so basically your first formula was doing what you wanted but the ToText was rounding up to 4 because you did not indiacate that in that function to use 2 decimal spaces.
IP IP Logged
bal1
Groupie
Groupie


Joined: 28 Nov 2012
Online Status: Offline
Posts: 44
Quote bal1 Replybullet Posted: 13 Jun 2013 at 4:00am
Brilliant...thank you!
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3701
Quote hilfy Replybullet Posted: 14 Jun 2013 at 7:42am
Actually, you can simplify this even further by using the format of the field to include the '%' instead of converting to text.  So, here's your formula:
 
If not IsNull({@TotalSampleByComponent}) and {@TotalSampleByComponent}) > 0 then
  {@TotalFailed}%{@TotalSampleByComponent}
else 0
 
NOTE:  I added the "If" statement to prevent division by zero errors that will cause the report to fail.
 
Once you add this to the report, right click on it and select "Format Field...".  On the Number tab, click on the "Customize" button.  On the new Number tab, select the correct decimals and rounding.  Then go to the "Currency Symbol" tab.  Enable the currency symbol and set its position to be on the right.  Then set the actual symbol to "%".  This will give you the format you're looking for without having to convert the number to text.
 
-Dell
IP IP Logged
bal1
Groupie
Groupie


Joined: 28 Nov 2012
Online Status: Offline
Posts: 44
Quote bal1 Replybullet Posted: 14 Jun 2013 at 8:37am
Thanks Dell!
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.027 seconds.