Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,

Iam facing a different problem which I was unable to figure out. I have a model with decimal parameter.

C#
public class Equipment
{
 public decimal Cost { get; set; }
public string Test1 { get; set; }
public string Test { get; set; }
}


In WebApi controller I have a method which will accept this list of Equipment like below.

C#

[HttpPost]
	    [Route("ProjectEquipments/Import")]
	    public async Task<HttpResponseMessage> Import([FromBody] List<Equipment> equipments)
	    {
 code..
}


When hit the method from post man by sending like below.. Im getting cost value as 72. Not sure where it is getting converted. Can any one help me on this?

C#
[
  {
    "Cost": 0110,
    "Test": "string",
    "Test1": "string",
 
  }
]


Thank you so much for the help!!

What I have tried:

Iam unable to figure where it is getting converted. Im getting converted value as input to my controller method.
Posted
Updated 11-Jan-17 23:04pm
Comments
F-ES Sitecore 12-Jan-17 4:58am    
It thinks "0110" is Octal (base 8). Maybe try without the leading 0 so just 110.

1 solution

0110 is the octal representation for the decimal value 72.

With C/C++, octal values are indicated by a leading zero. It seems that the input is parsed by a module build from C/C++ (C# does not support them).

The problem should get solved by removing the leading zero:
[
  {
    "Cost": 110,
    "Test": "string",
    "Test1": "string",
 
  }
]
 
Share this answer
 
Comments
NaVeN Kumar 12-Jan-17 5:29am    
If end user passes as 0110 it will take 72. Can we prevent that in any other way?
Jochen Arndt 12-Jan-17 5:41am    
If it is from a user input you probably get it as string. Then there should be also a check if the input is a valid number. If so, just use the numeric value and print that.

If not, you might:
- Convert the string to int and print that, or
- Remove leading zeroes from the string
Afzaal Ahmad Zeeshan 12-Jan-17 7:36am    
Good catch. 5ed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900