Home > Mobile >  jquery number plugin inserting as an integer into database
jquery number plugin inserting as an integer into database

Time:11-09

i've been using JQuery number plugins to help adding thousand separator in my text value, and i've been trying to insert the value as an integer, for example :

Nett Budget

image above is the input where i was trying to insert as a Integer into database.

but here is the value that being catched as a Integer after i convert it into integer :

$insert['nett_budget'] = intval($request->get('nett_budget'));

Catched

and here is when they are nvchar :

nvchar

here is the Jquery in index.php :

$('#nett_budget').number(true);

Is there a way to catch the whole number after the thousand separator as an Integer ? , or there maybe an alternate plugins that i can use, thanks!.

CodePudding user response:

Suppose you get this value;

var val = "222,222";

As your value is in string format you should replace your unnecessary character from your value like this;

var finalval = val.replace(",", "");

Here the first parameter is the character you want to remove, and the second parameter is the empty value. Through this technique, you can get the proper integer value in string format. Convert it into an integer if you need it.

First Modification: Here is the code with your code example, please check this;

set your value into a variable:

var _budget = $('#nett_budget').val(data.nett_budget);

Modify the value and replace unnecessary characters:

var _final_budget = _budget.replace(",", "");

Now use this _final_budget value instead of $('#nett_budget').val(data.nett_budget); this value. You can convert it into an integer.

  • Related