[Archive] [C#] How do i convert from a string to double? [Resolved]
[Archive] [C#] How do i convert from a string to double? [Resolved]
Archived author: barncastle • Posted: 2016-06-02T16:32:03+00:00
Original source
Everything that you're doing is correct however the reason you're missing the trailing zero is because the compiler is rightly removing it as it is irrelevant. 2.0 is exactly the same as 2.
If you want to keep them you need to use a string formatter on the double such as scale.ToString("0.00").
I'm on a phone at the moment so can't provide a decent example but look up string formatters in Google. It might also be worth looking at the Microsoft C# video tutorials as they're really good and cover this sort of thing.
On a side note; if this is a production project I'd suggest looking up the TryParse method as well as it allows you to handle bad user input.
Quote: 27 minutes ago, barncastle said:thanks
Everything that you're doing is correct however the reason you're missing the trailing zero is because the compiler is rightly removing it as it is irrelevant. 2.0 is exactly the same as 2.
If you want to keep them you need to use a string formatter on the double such as scale.ToString("0.00").
I'm on a phone at the moment so can't provide a decent example but look up string formatters in Google. It might also be worth looking at the Microsoft C# video tutorials as they're really good and cover this sort of thing.
On a side note; if this is a production project I'd suggest looking up the TryParse method as well as it allows you to handle bad user input.
Archived author: dashker • Posted: 2016-06-02T16:59:57+00:00
Original source
Quote: 27 minutes ago, barncastle said:thanks
Everything that you're doing is correct however the reason you're missing the trailing zero is because the compiler is rightly removing it as it is irrelevant. 2.0 is exactly the same as 2.
If you want to keep them you need to use a string formatter on the double such as scale.ToString("0.00").
I'm on a phone at the moment so can't provide a decent example but look up string formatters in Google. It might also be worth looking at the Microsoft C# video tutorials as they're really good and cover this sort of thing.
On a side note; if this is a production project I'd suggest looking up the TryParse method as well as it allows you to handle bad user input.