Author |
Message |
crystalnewbie33
Newbie
Joined: 08 Jan 2014
Online Status: Offline
Posts: 29
|
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 Logged |
|
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
|
Posted: 08 Jan 2014 at 12:07pm |
round (result,2)
|
IP Logged |
|
crystalnewbie33
Newbie
Joined: 08 Jan 2014
Online Status: Offline
Posts: 29
|
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 Logged |
|
crystalnewbie33
Newbie
Joined: 08 Jan 2014
Online Status: Offline
Posts: 29
|
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 Logged |
|
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
|
Posted: 09 Jan 2014 at 4:25am |
what is your code for the "formula that performs the calculation"?
|
IP Logged |
|
crystalnewbie33
Newbie
Joined: 08 Jan 2014
Online Status: Offline
Posts: 29
|
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 Logged |
|
kostya1122
Senior Member
Joined: 13 Jun 2011
Online Status: Offline
Posts: 475
|
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 Logged |
|
lockwelle
Moderator
Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
|
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 Logged |
|
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
|
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 Logged |
|
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
|
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 Logged |
|
|