I have $45.00 as string and need to get 45 out of that. following is working... How do I write this in one line?
var x= "$45.00" ,cents =/\.00$/;
var z= x.replace(/^\$/,'');
z = z.replace(cents,'');
I have $45.00 as string and need to get 45 out of that. following is working... How do I write this in one line?
var x= "$45.00" ,cents =/\.00$/;
var z= x.replace(/^\$/,'');
z = z.replace(cents,'');
Basically, the .replace()
calls can be daisy-chained, with the second one acting on the results of the first:
var x = "$45.00", cents = /\.00$/, z = x.replace(/^\$/, '').replace(cents, '');
If the question is that straight forward you can simply use this one line to get the left of the dot value.
var x= "$45.00".split('$')[1].split('.')[0];
Explanation:
I think it's pretty straightforward but tried to be as through as possible.