Reputation: 275
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)?
Upvotes: 5
Views: 531
Reputation: 101681
This should work:
float f = 2.99F;
string s = f.ToString("c2");
var number = float.Parse(s, NumberStyles.AllowCurrencySymbol
| NumberStyles.Currency);
Upvotes: 8