Home > Mobile >  What is the data type for money in ASP.NET Core
What is the data type for money in ASP.NET Core

Time:04-29

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 money, 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 money)) as HighestBid from Bids where PostId = @ip_Postid
     and Amount != ''
 select min(cast(Amount as float)) as HighestBid from Bids where PostId = @ip_Postid
     and Amount != ''

API Output :

public class GetUserBidOutPut
{
    [Key]
    public int? HighestBid { get; set; }
}

CodePudding user response:

Use Decimal in .NET for exact numeric types with fixed decimal places, not int.

CodePudding user response:

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; }
}
  • Related