# how does can be convert into two decimal places • ### Question

• User-1355965324 posted

I have the following code an I want to convert it into two decimal places like  Please help

SalaryPerHour = 20000.0000

SalaryPerMonth= 1000.0000

I want to convert it as 20000.00 and 1000.00

HourlySalary = Convert.ToDecimal(row["SalaryPerHour"].ToString()),
MonthlySalary = Convert.ToDecimal(row["SalaryPerMonth"].ToString()),
YearlySalary = Convert.ToDecimal(row["SalaryPerYear"].ToString()),

Tuesday, January 29, 2019 9:01 AM

• User-1355965324 posted

I corrected  using Math.Round

HourlySalary = Math.Round(Convert.ToDecimal(row["SalaryPerHour"].ToString()),2)

Thanks

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Tuesday, January 29, 2019 11:41 AM

### All replies

• User-1355965324 posted

I corrected  using Math.Round

HourlySalary = Math.Round(Convert.ToDecimal(row["SalaryPerHour"].ToString()),2)

Thanks

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Tuesday, January 29, 2019 11:41 AM
• User-376018714 posted

Hi

You dont need Math.Round() for what you are trying to do. C# has various numeric formatters. And the one you need is called as Fixed Point format.

Please go through the documentation here: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#the-fixed-point-f-format-specifier

In Short - when you do ToString() use the format "F2" … that will format the number to 2 decimal points.

Hope this helps.

Tuesday, January 29, 2019 6:07 PM