'What is the data type in ASP.NET Core for decimal(18,2) in sql
I have a Amount column in database which is in Varchar datatype, I am retrieving the data from table and I am casting for the amount should be returned as (12345.0,111.00) like this, so here I am casting with decimal, but in my ASP.NET Core the output data type is mismatching. How can I get the output like this (12345.0,111.00) from both API and database.
select max(cast(Amount as DECIMAL(18,2))) as HighestBid from Bids where PostId = @ip_Postid
and Amount != ''
select min(cast(Amount as DECIMAL(18,2))) as HighestBid from Bids where PostId = @ip_Postid
and Amount != ''
API Output :
public class GetUserBidOutPut
{
[Key]
public decimal? HighestBid { get; set; }
}
Solution 1:[1]
Use Decimal in .NET for exact numeric types with fixed decimal places, not int.
Solution 2:[2]
Why are you using int and float in your Model and SQL? use DECIMAL instead.
select max(cast(Amount as DECIMAL(18,2))) as HighestBid from Bids where PostId = @ip_Postid
and Amount != ''
select min(cast(Amount as DECIMAL(18,2))) as HighestBid from Bids where PostId = @ip_Postid
and Amount != ''
And,
public class GetUserBidOutPut
{
[Key]
public Decimal? HighestBid { get; set; }
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | David Browne - Microsoft |
| Solution 2 | heyharshil |
