Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign string value for decimal value

_item = new OutTYonetimOzet();

_item.Banka = Convert.ToDecimal(" "); 

liste.Add(_item);

There is a list called liste. In List item Banka named element is decimal value. I want to show the empty string when I show it on the screen. But this code is getting an error that can not be cast. What is the problem.

Error message is:

Input string was not in a correct format.


1 Answers

There's no such thing as a "blank decimal". decimal cannot have a value that is "blank" - it always has a numeric value. Convert.ToDecimal(" ") is nonsensical - there is nothing it can return that makes sense.

You could try using a Nullable<decimal> (aka decimal?) perhaps; i.e.

public decimal? Banka {get;set;}

and

_item.Banka = null;
like image 145
Marc Gravell Avatar answered Mar 18 '26 18:03

Marc Gravell