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

Find number of decimal places

Status
Not open for further replies.

PAULCALLAGHAN

Technical User
Sep 4, 2001
165
CA
I'm using Crystal Reports version 8.5.

A report I have made prints a field that will vary with the number of decimal places input to it. It is not a calculated field.

I would like to format this field conditionally to display the number of decimal places used. Therefore I need to come up with a formula that will calculate this.

I've tried many approaches but can't seeem to get it. I've tried calculating the difference between the field and the field rounded to zero decimal places, convert to text then provide the length. But this result gives the places before and after the decimal place.

Help, please!
 
I think the following should work:

if length(mid(totext({table.number}),instr(totext({table.number}),".")+1)) = 4 then totext({table.number},4) else
if length(mid(totext({table.number}),instr(totext({table.number}),".")+1)) = 3 then totext({table.number},3) else
if length(mid(totext({table.number}),instr(totext({table.number}),".")+1)) = 2 then totext({table.number},2) else
if length(mid(totext({table.number}),instr(totext({table.number}),".")+1)) = 1 then totext({table.number},1) else
totext({table.number},0)

You would have to adapt this to allow for more than more decimals.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top