Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Truncating a Formula Field Post Reply Post New Topic
Page  of 2 Next >>
Author Message
crystalnewbie33
Newbie
Newbie


Joined: 08 Jan 2014
Online Status: Offline
Posts: 29
Quote crystalnewbie33 Replybullet Topic: Truncating a Formula Field
    Posted: 08 Jan 2014 at 11:17am
I've looked through a lot of forums and can't quite find the right answer. I've created a formula that performs a calculation. I want the result of the calculation to only keep two decimals. I know you can change the number of decimals shown but I am totaling these calculations at the bottom of the report and I would like to total them without adding the extra decimals. I've tried to truncate the field under the customize, decimals, but keep getting error message of 'Bad Formula Result.' Any help would be greatly appreciated.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 08 Jan 2014 at 12:07pm
round (result,2)
IP IP Logged
crystalnewbie33
Newbie
Newbie


Joined: 08 Jan 2014
Online Status: Offline
Posts: 29
Quote crystalnewbie33 Replybullet Posted: 09 Jan 2014 at 3:18am
Thank you for the response. I guess maybe I don't know where to put this formula as I am still getting the 'Bad Formula Result' message. Please explain where to place it if you will. Also, by 'result', do you mean the formula field? I put it in like this:
round ({@field},2)
Thanks again
IP IP Logged
crystalnewbie33
Newbie
Newbie


Joined: 08 Jan 2014
Online Status: Offline
Posts: 29
Quote crystalnewbie33 Replybullet Posted: 09 Jan 2014 at 3:20am
One other thought - maybe I have something wrong with my formula field? Do I need to declare the field to be a Number somewhere? I think it is automatically a String value but I'm not sure where (or if I need to) change this.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 09 Jan 2014 at 4:25am
what is your code for the "formula that performs the calculation"?
IP IP Logged
crystalnewbie33
Newbie
Newbie


Joined: 08 Jan 2014
Online Status: Offline
Posts: 29
Quote crystalnewbie33 Replybullet Posted: 09 Jan 2014 at 4:42am
Here is the formula:
IF {animalhist.Price_type} = "CWT" THEN
formula = ({animalhist.Bid_Price}*{animalhist.Weight})/100
ELSE
formula = {animalhist.Bid_Price}*{animalhist.Number_Head}
END if
IP IP Logged
kostya1122
Senior Member
Senior Member
Avatar

Joined: 13 Jun 2011
Online Status: Offline
Posts: 475
Quote kostya1122 Replybullet Posted: 09 Jan 2014 at 4:50am
try click edit formula and at the top find where it says basic syntax and change it with crystal syntax for
round formula.


Edited by kostya1122 - 09 Jan 2014 at 4:52am
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 09 Jan 2014 at 5:09am
I am guessing the DBlank would say:
IF {animalhist.Price_type} = "CWT" THEN
formula = ({animalhist.Bid_Price}*{animalhist.Weight})/100
ELSE
formula = {animalhist.Bid_Price}*{animalhist.Number_Head}
END if
formula = round(formula,2)


I don't use the Basic Syntax when coding reports, so this looks odd to me. I have gotten used to the Crystal syntax
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 09 Jan 2014 at 5:09am

I don't use Basic syntax at all.

A Crystal syntax version of this would be :
 
ROUND(IF {animalhist.Price_type} = "CWT" THEN (({animalhist.Bid_Price}*{animalhist.Weight})/100) ELSE ({animalhist.Bid_Price}*{animalhist.Number_Head}),2)

Edited by DBlank - 09 Jan 2014 at 5:13am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 09 Jan 2014 at 5:12am
It looks like lockwelle has a good Basic syntax option with : 
 
IF {animalhist.Price_type} = "CWT" THEN
formula = ({animalhist.Bid_Price}*{animalhist.Weight})/100
ELSE
formula = {animalhist.Bid_Price}*{animalhist.Number_Head}
END if
formula = round(formula,2)


Edited by DBlank - 09 Jan 2014 at 5:14am
IP IP Logged
Page  of 2 Next >>
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.