Page 1 of 1
Format decimal to a "00000" string
Posted: Mon Jan 30, 2017 10:28 am
by Jennypi
Hi,
I'm a bit lost with the format function.
I'm trying to convert a decimal to a string of 5 characters.
For example: convert "101.000" to "00101".
How can I do that? I tried
Code: Select all
Format("{00000}",((int)MyValue).ToString())
but with no success.
Thanks for your help!
Re: Format decimal to a "00000" string
Posted: Mon Jan 30, 2017 1:29 pm
by Alex K.
Hello,
Please try to use the following expression:
Code: Select all
{String.Format("{0:00000}", (int)MyValue)}
Thank you.
Re: Format decimal to a "00000" string
Posted: Mon Jan 30, 2017 2:39 pm
by Jennypi
Working great, thank you!
I tried to use a similar code to convert a string "a" into a string "00a":
Code: Select all
String.Format("{0:000}", MyTextValue)
but it's not working.
Where is it wrong? This format feature is not easy to understand for me!
Thanks!
Re: Format decimal to a "00000" string
Posted: Tue Jan 31, 2017 12:51 pm
by Alex K.
Re: Format decimal to a "00000" string
Posted: Tue Jan 31, 2017 1:00 pm
by Jennypi
Thanks for your reply but the link is not working.
I guess this is the link to the
MSDN webpage for method String.Format, but honestly, from what I understand, the code that I wrote should work:
"String.Format("{0:000}", MyTextValue)" should insert my string ("0") as a string of 3 characters ("000").
Unless I should write
"String.Format("{0:000}", (int)MyTextValue)"
?
Am I wrong?
Re: Format decimal to a "00000" string
Posted: Wed Feb 01, 2017 9:54 am
by HighAley
Hello.
Your formatting is for the numbers, but if you have string value, you should convert it to a number.
This code is processed by .Net Framework and works as in any other C# application.
Thank you.
Re: Format decimal to a "00000" string
Posted: Wed Feb 01, 2017 10:28 am
by Jennypi
Thanks, I've managed to get what I wanted.
(actually I don't know anything about c#, that's why I was asking for your help

)
Re: Format decimal to a "00000" string
Posted: Wed Feb 01, 2017 8:37 pm
by Alex K.
Hello
Ok.
Please let us know if you need any additional help.
Thank you.
Re: Format decimal to a "00000" string
Posted: Tue Jun 05, 2018 3:07 pm
by joaquinsuarez69
Hi, related to this problem i'm using {string.Format("{0:F2}",myValue)} and it works, but now i want to know if there's a way to use the value of a field instead of that number 2, because i need to adapt the number of decimals according a value received from the server
thank you
Re: Format decimal to a "00000" string
Posted: Fri Jun 08, 2018 6:30 am
by Lech Kulikowski
Hello,
You can add your own function on Code tab or in your code in which decimal numbers and column and return value in necessary format.
Thank you.