BOB: Business Objects Board
Not endorsed by or affiliated with SAP

Register | Login 

Want to sponsor BOB? 
Want to sponsor BOB? (Opens a new window)  

General Notice: No events within the next 45 days.

Reducing number of decimal places in string object


 
Search this topic... | Search Crystal Reports... | Search Box
Register or Login to Post    Forum Index -> Building Reports -> Crystal Reports  Previous TopicPrint TopicNext Topic
Author Message
AMIGD
Forum Member
Forum Member



Joined: 13 Jun 2019

Posts: 3



PostPosted: Thu Jun 13, 2019 8:39 am 
Post subject: 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:

Code:
{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.
Back to top
anil.ganga1
Principal Member
Principal Member



Joined: 04 Jul 2007
ASUG Icon
Posts: 484
Location: San Francisco


flag
PostPosted: Thu Jun 13, 2019 2:58 pm 
Post subject: Re: Reducing number of decimal places in string object

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.

_________________
Thanks,
Anil.

Business Objects 6.5/XIR2/3.X/4.X
Crystal Reports 9/XI/XIR2/XIR2A/2008/2011/2013/2016
Back to top
AMIGD
Forum Member
Forum Member



Joined: 13 Jun 2019

Posts: 3



PostPosted: Fri Jun 14, 2019 3:06 am 
Post subject: Re: Reducing number of decimal places in string object

anil.ganga1 wrote:
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.

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

Quote:
"Error in forumula <Qty_Per>,
'CDbl({Report_Extract.RPTL132}[54 to 68])'
The string is non-numeric.
Details: errorKind"


Any ideas?
Back to top
kevlray
Forum Associate
Forum Associate



Joined: 23 Jun 2010

Posts: 974
Location: California


flag
PostPosted: Mon Jun 17, 2019 8:39 am 
Post subject: Re: Reducing number of decimal places in string object

Are you absolutely certain that in all cases the sub string is numeric in all cases (no nulls)?
Back to top
AMIGD
Forum Member
Forum Member



Joined: 13 Jun 2019

Posts: 3



PostPosted: Mon Jun 17, 2019 9:44 am 
Post subject: Re: Reducing number of decimal places in string object

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.
Back to top
kevlray
Forum Associate
Forum Associate



Joined: 23 Jun 2010

Posts: 974
Location: California


flag
PostPosted: Mon Jun 17, 2019 11:55 am 
Post subject: Re: Reducing number of decimal places in string object

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]
Back to top
Display posts from previous:   
Register or Login to Post    Forum Index -> Building Reports -> Crystal Reports  Previous TopicPrint TopicNext Topic
Page 1 of 1 All times are GMT - 5 Hours
 
Jump to:  

Index | About | FAQ | RAG | Privacy | Search |  Register |  Login 

Get community updates via Twitter:

Not endorsed by or affiliated with SAP
Powered by phpBB © phpBB Group
Generated in 0.0290 seconds using 18 queries. (SQL 0.0029 Parse 0.0009 Other 0.0252)
CCBot/2.0 (https://commoncrawl.org/faq/)
Hosted by ForumTopics.com | Terms of Service
phpBB Customizations by the phpBBDoctor.com
Shameless plug for MomentsOfLight.com Moments of Light Logo