# Conditional Formula Based on Decimal places in a String

I have a string field that is displaying a numerical value.  Sometimes the input data has three decimal places (12.345) and sometimes it has two (12.34). I want to standardize the field so that it only displays two decimal places and truncates the third if present.  How can I do this? Also, the field (standardized to two decimal places), must be used in a concatenation formula with other string values.

Thanks!
###### Who is Participating?
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.

Professor of MIS at Penn State Erie and Owner, Millet SoftwareCommented:
ToText({yourNumericField}, 2, ",")

Change the last argument if you want a different thousand separator (or no separator).
0
Commented:
When you say truncates to 2 decimals, do you really mean that or is rounding ok?

Ido's formula will round.  If you want to truncate then use

ToText({Truncate(yourNumericField},2), 2, ",")

mlmcc
0
Commented:
Those suggestions are assuming that your field is numeric.  If, as you said, the field is actually a string, you'd need to convert it to a number first.  If the field only contains that number (eg. "12.345"), you can use Val to convert the string to a number.  Just replace {yourNumericField} in their examples with Val ({your field})

If the field could contain other characters (eg. "ab 12.345"), then converting it to a number will be more complicated.

James
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.

Author Commented:
Thank you all. It is a string and I am trying to truncate.  If I understand correctly, my formula would be:

ToText({Truncate(val({yourNumericField}),2), 2, ",")
0
Commented:
That looks good

mlmcc
0
Author Commented:
Thank you that worked perfectly!
0
###### 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
Crystal Reports

From novice to tech pro — start learning today.

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.