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.

Who is Participating?

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

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).
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, ",")

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.


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
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

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, ",")
That looks good

josslmpdAuthor Commented:
Thank you that worked perfectly!
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.