cancel
Showing results for 
Search instead for 
Did you mean: 

Truncating a number with decimals

Former Member
0 Kudos

I have created a field {@years} with the value -10 which was used as part of a formula. This part has worked fine. I also wanted to use {@years} as part of the report heading where -10 represented a time period. However, the number came up as -10.00. I used the formula Truncate(Abs({@years})) but only the Abs part seemed to work. The number came up as 10.00 instead of 10.

Is there a problem with the formula I'm using or with Crystal Reports X or something else?

Regards

Jorge

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

or if you're using it inside an HTML formatted text box as part

of a string you can say:

ToText({@years},0,"") ...and this will get rid of the decimal.

The Panda

Former Member
0 Kudos

Thanks Panda,

Your suggestion certainly removes the decimal places, however it leaves the number in the negative.

I tried to use Abs within your formula ToText(Abs({@years},0,"")) but it says that too many arguments have been given to the function. Any idea where I go to from here?

-


I thought to use Right (str, length) and it worked. I don't know if there is a more effecient way to do it but Right(ToText({@years},0,""),2) does the job. I now get 10 instead of -10.

Thanks Panda, would not have got this far without your help.

Regards

Jorge

Edited by: Jorge Guillen on Jul 14, 2008 9:38 AM

Former Member
0 Kudos

You said:

"I tried to use Abs within your formula ToText(Abs({@years},0,"")) but it says that too many arguments have been given to the function."

You've almost got it. Check that your parens are correct.

I haven't run this on my machine yet, but I see that

the Abs function is not ended after @years...you have } but not

) after that. See what I mean ?

The Panda

Here you go, I just ran it. First, here is the Abs function:

abs(-2.0)

Then I place the abs function inside the ToText function:

ToText(abs(-2.0), 0, "")

Notice how (-2.0 is closed off with a paren - ")".

Yours is not closed off and the compiler thinks you are throwing (...giving) too many parameters to the Abs function (...which you are :).

The Panda

Answers (3)

Answers (3)

Former Member
0 Kudos

You should be able to double-click inside the text field in design view, then select the formula name within the field, right click the formula name, and click Format Field, go to the Number tab, etc.

Former Member
0 Kudos

Thanks for your help Panda

Former Member
0 Kudos

Jorge

May not be the best way, but another way to turn a negative number to a positive it to multiply the field by (-1).

fritzfeltus
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Jorge,

This is due to your default system number formatting. To customize:

Right-click the field in your header, select Format Field, Number tab, and choose the correct number formatting you require.

Cheers,

Fritz

Former Member
0 Kudos

Hi Fritz,

Your suggestions would work fine except I have placed the field within a text object and there is no numbers tab when I right click. I guess it is treating it as text.

Regards

Jorge

Former Member
0 Kudos

Apologies Fritz,

I had another look at your advice after a suggestion by another forum member and you were right, except in Report view the wording was "Format Text..." and in Design View the wording was "Format {@fieldname}". Either way it worked but now I can't give you full points. Again my apologies.

Regards

Jorge

fritzfeltus
Product and Topic Expert
Product and Topic Expert
0 Kudos

Haha, thanks Jorge, you don't have to apologize for not giving points... the aim was to help you solve your problem

Cheers,

Fritz