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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Number Format Problem 1

Status
Not open for further replies.

kernal

Technical User
Feb 27, 2001
415
0
0
US
I'm using Crystal 8 with csv file.

I have a number type field with text in a formula. If there isn't any cents then I want the number without the decimals. If there is cents then I want the decimals to show.

Example:

Amount
129.00
7.50

Results wanted (have the words 'Fee: '+{amount field} in a formula):

Fee: 129
Fee: 7.50

Help is appreciated. Thanks
 
if {yourfield} = int({yourfield}) then "Fee: "&totext({yourfield},0}

else

"Fee: "&totext({yourfield},2}

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports

"If you have a big enough dictionary, just about everything is a word"
--Dave Barry
 
thanks dgillz. It worked great.
 
I would convert the number to a string using totext() and then use instr() to locate the position of the decimal point
IE

if RIGHT(totext(fld),2) = "00" then <<checks that number has no cents [/color red]
left(totext(fld),(instr(totext(fld),".")-1)) <<locates decimal point and trims to it[/color red]
else fld

I hope that helps, theres probably an easier way.

Stuart
 
Stupot's formula will not work because the then and else values must be the same data type. Not the corrections in red below:

if RIGHT(totext({fld}),2) = "00" then
left(totext({fld}),(instr(totext({fld}),".")-1))
else [red]totext([/red]{fld}[red])[/red]


Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports

"If you have a big enough dictionary, just about everything is a word"
--Dave Barry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top