Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting % to number

Status
Not open for further replies.

lthomas6

MIS
Aug 22, 2007
87
US
I am trying to convert a string field (100%) in the database to a number. I am also looking to see if this field isnull then make it 0. I tried the following formula:

if isnull({Command.Percentage}) then 0 else
ccur({Command.Percentage})

It gives me the error message "The string is non-numeric"
I am using Crysal 10 with a SQL database. The actual field has % in it. ie: 100%
 
if isnull({Command.Percentage}) then 0 else
ccur(
replace({@julian date},"%","")
)

_____________________________________
Crystal Reports XI Developer Version
Intersystems Cache 5.X ODBC connection

 
if isnull({Command.Percentage}) then 0 else
ccur(
replace({Command.Percentage},"%","")
)

sorry about the first post I was working on a different project and pasted the wrong field

_____________________________________
Crystal Reports XI Developer Version
Intersystems Cache 5.X ODBC connection

 
That works, thanks for your help however if I try to multiply this field with another field (contractamt) to get the %ofSale it gives me the error message "A number is required" for @percentage.

I am using the below for the %ofSale formula:

if ({@contractamt} * {@percentage} )= 0 then
0 else ({@contractamt} * {@percentage})
 
can you post your formula for {@contractamt}? go ahead and post the formula for {@percentage} as well.

By the way, I only used ccur because that what you had in your intitial post. To get a percent you can use as a better multiplier change the formula to

tonumber(
replace({@julian date},"%","")
)/100

_____________________________________
Crystal Reports XI Developer Version
Intersystems Cache 5.X ODBC connection

 
My formula for contractamt = if isnull({Command.ContractAmount}) then 0
else Ccur({Command.ContractAmount})

My formula for percentage = if isnull({Command.Percentage}) then 0 else
ccur(
replace({Command.Percentage},"%","")
)

My formula for PercentofSale = {@contractamt} * {@percentage} . This is where it fails.
 
ok I didnt understand at first why this didnt work. so I tried to * two formulas which had both been converted using ccur and got the same results you did. However if I changed the formula to wha tI suggested in my last post it worked fine. Sorry it took so long to get back to you.

tonumber(
replace({Command.Percentage},"%","")
)/100

_____________________________________
Crystal Reports XI Developer Version
Intersystems Cache 5.X ODBC connection

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top