How to convert a numeric data type with 1 digit decimal to 2 decimals with leading zero.

For Instance
Assuming that I got a result from a calculation 7.7 which means 7.07, how to add the leading zero or how to convert to a 2 decimal points with leading zero

The Math.Round() rounds it to 7.70 and or 8.0 and what I am looking for to be 2 decimal points with the leading zero, in other word the result should be 7.07

I will really appriciates for sample code that converts from 7.7 to 7.07

The Math.Round() rounds it to 7.70 and or 8.0 and what I am looking for to be 2 decimal points with the leading zero, in other word the result should be 7.07

I will really appriciates for sample code that converts from 7.7 to 7.07

In my opinion. it is more reasonable to get the result 7.70 instead of 7.07 because 7.70 equals to 7.7.

If you have special requirement convering the 7.7 to 7.07, I suggest you could conver the number to string and use split() method to split the number and add a “0” character to the split number.

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

Thank you very much Brando for your help and sample code, I understand that in the real math world 7.7 = 7.70 but in this case calculating seconds of an hour we all know that an hour is equal to 60 minutes and 60 minutes = 60 seconds and for some reason
some result was giving me 1 decimal and was not putting the leading zero.

this is great I was having problem with numeric results with 1 decimal while calculating seconds.

Member

55 Points

166 Posts

## How to add to a numeric data type with 1 digit decimal a 2 decimal with leading zero.

Jul 09, 2018 11:56 PM|msdevm|LINK

How to convert a numeric data type with 1 digit decimal to 2 decimals with leading zero.

For Instance

Assuming that I got a result from a calculation 7.7 which means 7.07, how to add the leading zero or how to convert to a 2 decimal points with leading zero

The Math.Round() rounds it to 7.70 and or 8.0 and what I am looking for to be 2 decimal points with the leading zero, in other word the result should be 7.07

I will really appriciates for sample code that converts from 7.7 to 7.07

Thanks

Star

9671 Points

3077 Posts

## Re: How to add to a numeric data type with 1 digit decimal a 2 decimal with leading zero.

Jul 10, 2018 03:15 AM|Brando ZWZ|LINK

Hi msdevm,

In my opinion. it is more reasonable to get the result 7.70 instead of 7.07 because 7.70 equals to 7.7.

If you have special requirement convering the 7.7 to 7.07, I suggest you could conver the number to string and use split() method to split the number and add a “0” character to the split number.

More details, you could refer to below codes:

Result:

Best Regards,

Brando

Please remember to click "Mark as Answer" the responses that resolved your issue.

If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

Member

55 Points

166 Posts

## Re: How to add to a numeric data type with 1 digit decimal a 2 decimal with leading zero.

Jul 10, 2018 11:13 AM|msdevm|LINK

Thank you very much Brando for your help and sample code, I understand that in the real math world 7.7 = 7.70 but in this case calculating seconds of an hour we all know that an hour is equal to 60 minutes and 60 minutes = 60 seconds and for some reason some result was giving me 1 decimal and was not putting the leading zero.

this is great I was having problem with numeric results with 1 decimal while calculating seconds.

Thanks again Brando