0

I have to set 3 decimal place in SQL Server 2005.i can set it from only model part .But In sql server set datatype of Salary is decimal.

When I set like

public decimal Salary { get; set; }

It want to save the database like 21000.000 not 21000. If I put 30000.75,then it would be saved to 30000.750.

Monica
  • 607
  • 4
  • 12
  • 31
  • If you're using EF, [set the precision](http://stackoverflow.com/questions/3504660/entity-framework-code-first-decimal-precision-and-scale) but otherwise ... just present it with as many decimal places as you need. – ta.speot.is Apr 19 '13 at 08:05

2 Answers2

2

The easiest way to solve your problem is to set the Salary datatype to decimal(18, 3). So even if you insert a value 30000.75123 only the first three decimal digits will be saved - 30000.750. If you insert a whole number 21000 then the value in the database will be 21000.000.

von v.
  • 16,868
  • 4
  • 60
  • 84
0

Even me faced this problem , one thing you can do with before sending to the database you will have to convert the value into 3 decimal places . you can do this by -

txtsalary.Text = String.Format("{0:0.000}", Salary);

or

decimal Salary ;

if (Decimal.TryParse(txtsalary.Text, out Salary )) // Returns true on valid input, on top of converting your string to decimal.
{
    // ... code that is doing stuff with the decimal value ...

    txtsalary.Text = String.Format("{0:0.000}", Salary );
}
else
{
    // do your error handling here.
}
sarvesh kushwaha
  • 342
  • 1
  • 3
  • 19