# how to set Decimal Fraction more than 2 digits(C# to SQL). [Answered]RSS

## 4 replies

Last post Sep 11, 2015 06:03 AM by Krish Kannaa

• Krish Kannaa

Member

2 Points

10 Posts

### how to set Decimal Fraction more than 2 digits(C# to SQL).

Sep 10, 2015 08:48 AM|Krish Kannaa|LINK

Hi All,

When I tried to insert decimal value(0.9232) into SQL Table inserting only 2 digits(0.92). Please help me on this.

FYI

input : {"Currency":"USD","ShipmentNumber":"xyz","CompanyCode":"HYW","BuyRate":0.9232,"BaseSellRate":0,"SellRate":0.903,"QuoteNumber":""}

Data model :  public decimal? BuyRate { get; set; }

Inserted  in DB like : BuyRate  = 0.920000000  and SellRate : 0.900000000

decimal sql

• Krunal Parek...

All-Star

15372 Points

2074 Posts

### Re: how to set Decimal Fraction more than 2 digits(C# to SQL).

Sep 11, 2015 02:56 AM|Krunal Parekh|LINK

Hello Krish Kanna,

What is your SQL table column type is it decimal ? you need to set proper necessary precision and scale. if you are using model check the decimal's precision and scale.

Please see: decimal and numeric (Transact-SQL)

Here is an example.

```DECLARE @Test TABLE
(
RATE DECIMAL(5,4)
)

INSERT @Test
SELECT 0.9232
UNION ALL
SELECT 0.903

SELECT * FROM @Test

//Output
RATE
0.9232
0.9030```

Hope this helps.

With Regards,

Krunal Parekh

decimal sql

Krunal

MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue.
• Krish Kannaa

Member

2 Points

10 Posts

### Re: how to set Decimal Fraction more than 2 digits(C# to SQL).

Sep 11, 2015 04:52 AM|Krish Kannaa|LINK

Hi Krunal,

Thanks for your response.

I'm inserting record using C# Entity Framework. while inserting from SQL Mgmt Studio, It is working fine. But using C# Entity Framework, the output was came like that.

Please advice on this.

Note : Column Type

`Buy_Rate DECIMAL(18,9) `

decimal sql

• Krunal Parek...

All-Star

15372 Points

2074 Posts

### Re: how to set Decimal Fraction more than 2 digits(C# to SQL).

Sep 11, 2015 05:31 AM|Krunal Parekh|LINK

Hello Krish Kannaa,

If you are using code first please see this :http://stackoverflow.com/questions/3504660/decimal-precision-and-scale-in-ef-code-first

http://www.itworld.com/article/2909612/working-with-decimal-precision-in-net-with-mssql-server-and-entity-framework.html

For database first open Model Designer. And then find yourtable > column then check its properties you should find type, precision etc.

Hope this helps.

With Regards,

Krunal Parekh

decimal sql

Krunal

MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue.
• Krish Kannaa

Member

2 Points

10 Posts

### Re: how to set Decimal Fraction more than 2 digits(C# to SQL).

Sep 11, 2015 06:03 AM|Krish Kannaa|LINK

Thank you Krunal. With your help I found the answer.

decimal sql