skip to Main Content

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

2

Answers


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

    Login or Signup to reply.
  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; }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search