Fomatt a string field in crystal to two decimal places

We are trying to format a string field in crystal reports to 2 decimal place.  We are not able to do from SQL as the code is copy written therefore we are having problems.  The fields is a number example 802.35000000, we would like to truncate the ending zeros.  We have tried to use TOTEXT but it only comes back with to many arguments for function.   We tried the below a   Nothing is working

If IsNull({Rpt_JournalTransactionSp;1.TcDebit}) Or
   InStr({Rpt_JournalTransactionSp;1.TcDebit}, " ") = 0 Then
   "0"
else
 TOtext({Rpt_JournalTransactionSp;1.TcDebit},2)
stevendeveloperAsked:
Who is Participating?
 
mlmccConnect With a Mentor Commented:
Try this one

If IsNull({Rpt_JournalTransactionSp;1.TcDebit})  then
   ''
Else If IsNumeric({Rpt_JournalTransactionSp;1.TcDebit}) Then
     CStr(ToNumber({Rpt_JournalTransactionSp;1.TcDebit}), 2)
Else
   {Rpt_JournalTransactionSp;1.TcDebit}

Open in new window

0
 
Darrell PorterEnterprise Business Process ArchitectCommented:
Try
If IsNull({Rpt_JournalTransactionSp;1.TcDebit}) Or 
   InStr({Rpt_JournalTransactionSp;1.TcDebit}, " ") = 0 Then
   "0"
else 
 TOtext({Rpt_JournalTransactionSp;1.TcDebit},2,"")

Open in new window


If this does not work, try a simpler approach to ensure type.

If IsNull({Rpt_JournalTransactionSp;1.TcDebit}) Or 
   InStr({Rpt_JournalTransactionSp;1.TcDebit}, " ") = 0 Then
   "0"
else 
 Round({Rpt_JournalTransactionSp;1.TcDebit},2)

Open in new window

0
 
stevendeveloperAuthor Commented:
getting     error " a number or currency amount is required here"  Round({Rpt_JournalTransactionSp;1.TcDebit},2)
and on the top one getting the error "to many arguments for this function"  TOtext({Rpt_JournalTransactionSp;1.TcDebit},2,"")

our version of crystal is 2013
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mlmccCommented:
The field is already text so you need to convert it to a number

Try
ToNumber({Rpt_JournalTransactionSp;1.TcDebit})

You can then format it as 2 decimals

If you want it as a string then use

CStr(ToNumber({Rpt_JournalTransactionSp;1.TcDebit}), 2)

If you have strings that aren't numeric you can use VAL to convert what it can.

mlmcc
0
 
stevendeveloperAuthor Commented:
Thanks for the help but neither is working with error

The string is non-numeric.  

I don't think that we will be able to correct this problem since I am unable to do it from SQL.
0
 
mlmccCommented:
So the string can have non-numeric characters in it?

The example you provided has only numeric characters so it should convert with VAL or TO_NUMBER.

mlmcc
0
 
stevendeveloperAuthor Commented:
The data I have scrolled only has numeric characters but there is much data.   What you are asking I cannot answer 100%.  Sorry.
0
 
mlmccCommented:
Do you get an error when you try the formulas?

mlmcc
0
 
stevendeveloperAuthor Commented:
yes we do
0
 
mlmccCommented:
Try it this way

If IsNumeric({Rpt_JournalTransactionSp;1.TcDebit}) Then
     CStr(ToNumber({Rpt_JournalTransactionSp;1.TcDebit}), 2)
Else
    {Rpt_JournalTransactionSp;1.TcDebit}

Open in new window


mlmcc
0
 
stevendeveloperAuthor Commented:
I tried it but it is "empty"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.