So i convert a float to a string, which is formatted as a currency.
float f = 2.99F;
string s = f.ToString("c2");
//s = 2.99 €
But when I want to convert it back to a float, it wouldn't be possible, because a float cant store the € symbol. So is there a way to convert the string back to a float, but it disregards the " €" (with the space)?
This should work:
float f = 2.99F;
string s = f.ToString("c2");
var number = float.Parse(s, NumberStyles.AllowCurrencySymbol
| NumberStyles.Currency);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With