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!
josslmpdAsked:
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.

Ido MilletProfessor 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
mlmccCommented:
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
James0628Commented:
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.

Start your 7-day free trial
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

josslmpdAuthor 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
mlmccCommented:
That looks good

mlmcc
0
josslmpdAuthor 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.