BusinessObjects Board

Reducing number of decimal places in string object

I’ve got a “Qty Per” string object which is displaying 6 decimal places on the report however I only want it to show 2 decimal places.

The formula for the string object is as follows:

{Report_Extract.RPTL132}[54 to 68]

I’ve done some googling and a lot of people are referring to a “number” tab in the format editor window where this can be changed but there is no number tab on this object that I can see.

Others have mentioned a “ToText” formula but I’m not sure how I would implement this. I did not create this report I am simply editing an existing one and I am very new to crystal reports.


AMIGD (BOB member since 2019-06-13)

First you need to convert your string to number. Use CDbl() function for this.

Create a formula: CDbl({Report_Extract.RPTL132}[54 to 68]) and place this formula into your report.

Example:
CDbl ("$120.20")
Returns the Number value of 120.2

Now, right click on this object and you will see Number tab to format the decimals.


anil.ganga1 :us: (BOB member since 2007-07-04)

[quote:37d65b0bf7=“anil.ganga1”]First you need to convert your string to number. Use CDbl() function for this.

Create a formula: CDbl({Report_Extract.RPTL132}[54 to 68]) and place this formula into your report.

Example:
CDbl ("$120.20")
Returns the Number value of 120.2

Now, right click on this object and you will see Number tab to format the decimals.
[/quote]

Thanks very much for this. It did appear to work but when I run the report I get the following error:

Any ideas?


AMIGD (BOB member since 2019-06-13)

Are you absolutely certain that in all cases the sub string is numeric in all cases (no nulls)?


kevlray :us: (BOB member since 2010-06-23)

As far as I’m aware this field should always be numeric and cannot be left empty.

This is a “qty per” field for a bill of materials - I have just tried to fill in the field on Part Master and it will only allow me to put in numbers, a period or a hyphen.

No other characters can be inputted. If I leave it blank it seems to allow me to progress but when I go back to it later it has defaulted to a 1.


AMIGD (BOB member since 2019-06-13)

Just as a check. I would put in an if statement to check to make sure CDbl({Report_Extract.RPTL132}[54 to 68] is numeric just to see where it fails

So something like this as a test formula.

if isnumeric(CDbl({Report_Extract.RPTL132}[54 to 68]) then ‘Good’ else
{Report_Extract.RPTL132}[54 to 68]


kevlray :us: (BOB member since 2010-06-23)