Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a problem during conversion of double to string and prevent trailing zeros.

there is a variable double maxPrice which have not defined how many decimal places it can. sometime like 12.30 sometime 12.00 or 12.120. So i need to convert the same value in string format and show in a report. but when i try to convert it truncates the trailing zero's.

Please let me know how i can prevent this.

What I have tried:

double digit = 12.00d;

Console.WriteLine(digit.ToString(CultureInfo.InvariantCulture));
Posted
Updated 26-May-17 1:43am
v2

1 solution

It looks the "G29" format specifier should do the trick, see, for instance: c# - Best way to display decimal without trailing zeroes - Stack Overflow[^].
 
Share this answer
 
Comments
Maciej Los 26-May-17 10:39am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900