how do i format a number in the crystal reports formula editor

imonfireDAMMIT
imonfireDAMMIT used Ask the Experts™
on
I have a formula field and i want the output to be this
( 3 @ 96 )

I am using a formula field with this code
If (table.No_of_Cables) Then
     "(" & Truncate(Table.No_of_Cables) & " @ " & Truncate( table.totalLength / table.No_of_Cables) & ")"

my result is this : (3.00 @ 96.00)     i need to remove the zeros. I tried the Truncate function, the Round function, and also the Int function

what am i doing wrong???
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Consultant
Most Valuable Expert 2011
Top Expert 2013
Commented:
You have to format the numbers before adding them to the string.  Try it this way

"(" & CStr(Truncate(Table.No_of_Cables),0) & " @ " & CStr(Truncate( table.totalLength / table.No_of_Cables),0) & ")"

You can also use ToText in the same way.

mlmcc
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
A little more explanation.

When you simply put a numeric field into a string like that Crysta, uses the defaultt or system number format which is generally 2 decimal places.

BY using CStr or ToText you can control the format of the number and thus the number of decimal palces.

ToText({SomeNumberField},# Decimal Places, Thousand Separator)
# Decimal places defaults to 2 or the system numeric default
Thousan Separator defaults to , or system default

mlmcc

Author

Commented:
I used TOTEXT and it worked great. Thanks for your help. YOU ROCK :-)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial