## 5 replies

Last post Apr 20, 2016 10:48 PM by robby32

• robby32

Member

280 Points

1000 Posts

### How can i keep leading zero in a decimal

Hi

I have the following ,

tempAmount = 0.623456

The output is .62345  , how can i keep it as 0.62345

Thanks

• anuj_koundal

Contributor

7095 Points

1966 Posts

### Re: How can i keep leading zero in a decimal

Use this:

```        string value = "0.62345";
value = string.Format("{0:00000000}", value);
Response.Write(value);```

Anuj Koundal
Asp .Net Tutorials | www.codingfusion.com
Bank IFSC Codes
Ajax Control Toolkit
• robby32

Member

280 Points

1000 Posts

### Re: How can i keep leading zero in a decimal

Hi ,

Thanks for the response , I am using the above format because I need it to work in multiple locales. So if you take Croation for example , it has the  comma as a decimal separator and a dot as thousand separator.

Thanks

• A2H

All-Star

50811 Points

9893 Posts

### Re: How can i keep leading zero in a decimal

#### Robby32

The output is .62345  , how can i keep it as 0.62345

You can try with the below code

`tempAmount.ToString("#,0.#" + "".PadRight(6, '#'))`

Sample Working Demo

Thanks,
Aje
My Blog | Dotnet Funda
• gerrylowry

Star

14297 Points

5797 Posts

### Re: How can i keep leading zero in a decimal

Will your value always be < zero?

Study "Custom Numeric Format Stringshttps://msdn.microsoft.com/en-us/library/0c899ak8(v=vs.110).aspx

```Double Robby32 = 0.623456;
Console.WriteLine(Robby32);
Console.WriteLine(Robby32.ToString());
Console.WriteLine(Robby32.ToString("0.00000"));
Console.WriteLine(Robby32.ToString("0.00000",
System.Globalization.CultureInfo.CreateSpecificCulture("da-DK")));```

output:

```0.623456
0.623456
0.62346
0,62346```

another example

```Robby32 = 0.1234;
Console.WriteLine(Robby32.ToString("0.00000"));
Console.WriteLine(Robby32.ToString("0.00000",
System.Globalization.CultureInfo.CreateSpecificCulture("da-DK")));
```

output:

```0.12340
0,12340```

larger number example:

```Robby32 = 12345.1234;
Console.WriteLine(Robby32.ToString("0.00000"));
Console.WriteLine(Robby32.ToString("0.00000",
System.Globalization.CultureInfo.CreateSpecificCulture("da-DK")));
```

output:

```12345.12340
12345,12340```

example to separate output into groups of three to left of decimal point:

```Robby32 = 12345.1234;
Console.WriteLine(Robby32.ToString("###,###,##0.00000"));
Console.WriteLine(Robby32.ToString("###,###,##0.00000",
System.Globalization.CultureInfo.CreateSpecificCulture("da-DK")));```

output:

```12,345.12340
12.345,12340```

example with even larger number:

```Robby32 = 12345678.12341234;
Console.WriteLine(Robby32.ToString("###,###,##0.00000"));
Console.WriteLine(Robby32.ToString("###,###,##0.00000",
System.Globalization.CultureInfo.CreateSpecificCulture("da-DK")));```

output:

```12,345,678.12341
12.345.678,12341```

:

B-)  Gerry Lowry, Chief Training Architect, Paradigm Mentors Learning never ends... +1 705-999-9195 wasaga beach, ontario canada TIMTOWTDI =.there is more than one way to do it
• robby32

Member

280 Points

1000 Posts