Format decimal to a "00000" string

Stimulsoft Reports.NET discussion
Post Reply
Jennypi
Posts: 361
Joined: Mon Nov 17, 2008 7:13 am
Location: France

Format decimal to a "00000" string

Post 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!
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Format decimal to a "00000" string

Post by Alex K. »

Hello,

Please try to use the following expression:

Code: Select all

{String.Format("{0:00000}", (int)MyValue)}
Thank you.
Jennypi
Posts: 361
Joined: Mon Nov 17, 2008 7:13 am
Location: France

Re: Format decimal to a "00000" string

Post 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!
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Format decimal to a "00000" string

Post by Alex K. »

Hello,

Please see the following article:
https://msdn.microsoft.com/en-us/librar ... .110).aspx

Thank you.
Jennypi
Posts: 361
Joined: Mon Nov 17, 2008 7:13 am
Location: France

Re: Format decimal to a "00000" string

Post 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?
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Format decimal to a "00000" string

Post 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.
Jennypi
Posts: 361
Joined: Mon Nov 17, 2008 7:13 am
Location: France

Re: Format decimal to a "00000" string

Post 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 :))
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Format decimal to a "00000" string

Post by Alex K. »

Hello

Ok.
Please let us know if you need any additional help.

Thank you.
joaquinsuarez69
Posts: 4
Joined: Tue Feb 27, 2018 5:23 pm

Re: Format decimal to a "00000" string

Post 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
Lech Kulikowski
Posts: 6243
Joined: Tue Mar 20, 2018 5:34 am

Re: Format decimal to a "00000" string

Post 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.
Post Reply