c# - A number validation issue. .5 is not a number but 0.5 is? -


this model gets validated.

public class estimateitem {     public string itemname { get; set; }     public string displayname { get; set; }     public string description { get; set; }     public string notes { get; set; }      [datatype(datatype.currency)]     //[displayformat(applyformatineditmode = true, dataformatstring = "{0:n2}")]     public decimal perunitcost { get; set; }     public string perunitdescription { get; set; }      [displayformat(applyformatineditmode = true, dataformatstring = "{0:n0}")]     [min(1, errormessage = "cannot zero")]     public int units { get; set; }      public string unitsdescription { get; set; }     public bool isenabled { get; set; }     public bool isbasedonhomesquarefootage { get; set; }      [datatype(datatype.currency)]     //[displayformat(applyformatineditmode = true, dataformatstring = "{0:c2}")]     public decimal cost { get; set; }      public list<estimateitemoption> options { get; set; }      public decimal itemtotal { get; set; } } 

this text box fills model.

@html.textboxfor(m => model.categories[c].estimategroups[g].estimateitems[i].perunitcost, new { @disabled = "disabled", @onchange = "costupdate(this);", @csttype = "perunit" }) 

this javascript handled when called @onchange

case 'perunit':     var = $(src).closest('.itemrow').find("input[csttype='cost']");     var gt = parsefloat(et.html().replace('$', '').replace(',', ''));     et.html(gt - parsefloat(it.val()));     if ($(src).closest('.itemrow').find('[hs]').attr('hs') == 'true') {         var nv = $(src).val();         if (nv == null || nv.length == 0) nv = 0;         it.val(math.round(nv * parsefloat($('#squarefootage').val()) * 100) / 100)         $(src).closest('.itemrow').find('.hcst').val(it.val());         et.html(currencyformatted(parsefloat(et.html()) + parsefloat(it.val())));     } else {         var nv = $(src).val();         if (nv == null || nv.length == 0) nv = 0;         it.val(math.round(nv * parsefloat($(src).closest('.itemrow').find("input[csttype='units']").val()) * 100) / 100)         $(src).closest('.itemrow').find('.hcst').val(it.val());         et.html(currencyformatted(parsefloat(et.html()) + parsefloat(it.val())));     }     break; 

i need know if why textbox not let me use decimal less 1 .5 says perunitcost has number

try force input number:

case 'perunit':     var input = $(src), // may cache you're using 6 times.         = input.closest('.itemrow').find("input[csttype='cost']"),         gt = parsefloat(et.html().replace('$', '').replace(',', '')),         nv = parsefloat(input.val(), 10); // parse float ensure number     et.html(gt - parsefloat(it.val()));     if (!nv) { // nv either number, or nan, using truthy/falsy determine if nan         nv = 0; // technically, 0 falsy sets 0 anyway, not issue.     }     if (input.closest('.itemrow').find('[hs]').attr('hs') == 'true') {         it.val(math.round(nv * parsefloat($('#squarefootage').val()) * 100) / 100)         input.closest('.itemrow').find('.hcst').val(it.val());         et.html(currencyformatted(parsefloat(et.html()) + parsefloat(it.val())));     } else {         it.val(math.round(nv * parsefloat(input.closest('.itemrow').find("input[csttype='units']").val()) * 100) / 100)         input.closest('.itemrow').find('.hcst').val(it.val());         et.html(currencyformatted(parsefloat(et.html()) + parsefloat(it.val())));     }     break; 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -