3 Replies Latest reply on Jan 14, 2014 10:17 AM by KK Molugu

# Syntax to format value as % with optional tens place

The formula snippit below formats a value as a percent:

...

THEN mid(str(round(min([Value]),3)),3,2) + "." + mid(str(round(min([Value]),3)),5,1)+  "%" else str(round(min([Value]),0))

.. .

So I get desired formats like 90.2%, 15.0%, but when the value is < 10% I get an undesirable '0' in the tens place, as in 09.2%.

How can I eliminate the 0 in the tens place when it's not needed?

Thank you!

• ###### 1. Re: Syntax to format value as % with optional tens place

As the combined string is a text value which is the resultant of two sub-strings, this will include "0", as the first sub-string has "0" in it. EX: "02" + "." + "6" + "%" = 02.6%

You can eliminate "0" but converting the sub-strings to an int first and then convert them back to str.

ex: ... str(int(mid(str(round(min([value]),3)),3,2))) + "." + str(int(mid(str(round(min([value]),3)),5,1))) +  "%"

Hope this helps;

..kk

• ###### 2. Re: Syntax to format value as % with optional tens place

That works perfectly. I just tacked the else statement back on (else str(round(min([Value]),0)) ) and all is well. Much thanks.

• ###### 3. Re: Syntax to format value as % with optional tens place

Glad to know. Can you please mark the answered.