Decimal.Round() can be used to round to 2 places, and it also keeps the value as a decimal. ![]() You can also use String.Format() to display a float value to 2 decimal places like float.ToString().įor example, change floatNumber.ToString("0.00") to String.Format("", decimalNumber) to instead of decimalNumber.ToString("0.00"). standard numeric, put commas in for numbers in the thousandsĬonsole.WriteLine(floatNumber.ToString( "n2")) 2 decimal places, the value is rounded offĬonsole.WriteLine(floatNumber.ToString( "0.00")) Ĭonsole.WriteLine(floatNumber.ToString( "f2")) If there is no decimal or only single decimal places, it will pad zero behind the decimal point. If there are more than 2 decimal places in your float number, it will round off to 2 decimal places. Use float.ToString() to display a float value to 2 decimal places. #EXCEL CONVERT COMMA TO DECIMAL HOW TO#How to display a number to 2 decimal places in C#įormatting a float value to 2 decimal places in C#ġ. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |