7
Valor = 19.90;
MyArray = valor.split(".");
the code hangs , whole variable, however if,
Valor = "19.90";
MyArray = valor.split(".");
alert(MyArray[0]) = 19;
alert(MyArray[1]) = 90;
I would like to know how to use the split in int variable , thank you.
According to solutions, from friends already reputed below, I edit my question to the following form.
No, in the above case, I have the function,
function splitNum (34.50 * 2){
var s = n.toFixed(2).split('.');
var n1 = parseInt(s[0], 10); // 19
var n2 = parseInt(s[1], 10); // 10
return n1+"."+n2;
}
will return me 69.0
But I need you to return 69.00 , how would that be possible ? thank you.
Settled, thank you have a great afternoon.
function splitNum (34.50 * 2){
var s = n.toFixed(2).split('.');
var n1 = parseInt(s[0], 10); // 19
var n2 = parseInt(s[1], 10); // 10
return s[0]"."s[1];
}
1: Javascript does not work with "int variable" - 2: you can create your own method
.split()
just like the original easily, see in my reply how.– Paulo Roberto Rosa
try something like that:
Valor = 19.90;MyArray = (valor).toString().split(".");
– Leandro Amorim
XY problem... If all you wanted was to format a number with two decimal places, just do
Valor.toFixed(2)
. You didn’t have to split up and then put it back together... :)– mgibsonbr
rsrsr , I’ve used v.toFixed(2); is that I use other functions besides this, rsrsr, thank you.
– Wilson Lavrador