4 Replies - 2110 Views - Last Post: 23 June 2013 - 04:18 PM Rate Topic: -----

#1 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 407
  • Joined: 04-January 11

Crystal Report Decimal Place

Posted 23 June 2013 - 09:40 AM

i'm not sure in which forum should I place this topic. I am developing a web application using ASP.NET with C#.NET. My question is about Crystal Reports.

It is a really simple question though I am not sure how to approach since I am new to coding in Crystal reports formula editor.

I have a field that accepts decimal values. I need to limit it at 2 decimal places so I used:

ToText(CurrentFieldValue,2)



If it does not contain decimal values, then it should not have the .00. I just do not know the best way to arrive on that.

I am thinking of using some split function (though I do not know if Crystal Report is capable of this) to check values after the decimal point. But I want to know if there's a better way to achieve the same result.

Is This A Good Question/Topic? 0
  • +

Replies To: Crystal Report Decimal Place

#2 jace75  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 31
  • Joined: 11-June 13

Re: Crystal Report Decimal Place

Posted 23 June 2013 - 12:12 PM

In C#, you would do something like this...


//Convert data to string in double format with 2 decimal places, and remove trailing zero(s)
string s = CurrentFieldValue.ToString("0.##");

//Assuming data has been tested as valid double with only one or zero decimal points

//If the number contains a decimal value...
if(s.Contains('.'){
     
     //check that value and add a zero to the value if only one decimal place is found. 
     //The only other possibilities at this point should be two decimal places or none, in which case we leave it.
     string[] array = s.Split('.');
     if(array[1].Length = 1){
        s += "0";
     }

}

//Display



hope that helps B)
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3806
  • View blog
  • Posts: 13,488
  • Joined: 12-December 12

Re: Crystal Report Decimal Place

Posted 23 June 2013 - 12:30 PM

Won't it be confusing, or misleading, if some values have two decimals but others have none?

This post has been edited by andrewsw: 23 June 2013 - 12:32 PM

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3806
  • View blog
  • Posts: 13,488
  • Joined: 12-December 12

Re: Crystal Report Decimal Place

Posted 23 June 2013 - 12:40 PM

It might be:

if CurrentFieldValue = Truncate(CurrentFieldValue,0) then 
    CurrentFieldValue
else
    ToText(CurrentFieldValue, 2)

but I've never used Crystal Reports ;)

You might want:

if CurrentFieldValue = Truncate(CurrentFieldValue,0) then 
    ToText(CurrentFieldValue, 0)
else
    ToText(CurrentFieldValue, 2)

This post has been edited by andrewsw: 23 June 2013 - 12:40 PM

Was This Post Helpful? 0
  • +
  • -

#5 jace75  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 31
  • Joined: 11-June 13

Re: Crystal Report Decimal Place

Posted 23 June 2013 - 04:18 PM

"Won't it be confusing, or misleading if some values have two decimals but others have none?"

Not if the goal is to display decimal values only when needed. Sometimes its considered unprofessional to be overly explicit.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1