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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

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
mlmccCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.