I am trying to convert 1200.00
to decimal
, but Decimal.Parse()
removes .00
. I've tried some different methods, but it always removes .00
, except when I supply a fraction different than 0.
string value = "1200.00";
Method 1
var convertDecimal = Decimal.Parse(value , NumberStyles.AllowThousands
| NumberStyles.AllowDecimalPoint | NumberStyles.AllowCurrencySymbol);
Method 2
var convertDecimal = Convert.ToDecimal(value);
Method 3
var convertDecimal = Decimal.Parse(value,
NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
How can I convert a string
containing 1200.00
to a decimal
containing 1200.00
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…