Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
How to multiply two decimals of type string javascript

I want to multiply these two values ​​of type string

values 1 = "$10.99"

values 2 = "$20.8"

var x = document.getElementById("Text1");
var y = document.getElementById("Text2");
var tointx = x.Value
var tointy = y.Value
var z = tointx * tointy
var result = z.reduc((r, e) => r + +e.replace(',', '.'), 0)
alert(result);
<input id="Text1" value="$10.99" />

<input id="Text2" value="$20.8" />

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Several things

  1. .value JS is case sensitive
  2. $ sign needs to go
  3. reduce is misspelled too but not needed
  4. Are you sure you want ints?

const x = document.getElementById("Text1").value;
const y = document.getElementById("Text2").value;
let tofloatx = +x.slice(1); // unary plus will convert to number but so will multiplication
let tofloaty = +y.slice(1)
let z = tofloatx * tofloaty
console.log("float",z,"int",Math.round(z))
<input id="Text1" value="$10.99" />

<input id="Text2" value="$20.8" />

about 4 years ago · Juan Pablo Isaza Report

0

multiplyFields();

function multiplyFields( ) {
 var x = Text1.value,
     y = Text2.value,
     z = x.match( /[0-9.]+/ ) * y.match( /[0-9.]+/ );

    alert( z );
}
<input id=Text1 value=$10.99 >
<input id=Text2 value=$20.80 >

about 4 years ago · Juan Pablo Isaza Report

0

Is this what you needed?

let x = "$10.99"
let y = "$20.8"
let moneyToNb = function(money) {return Number(money.replace("$",""))}
let intX = moneyToNb(x)
let intY = moneyToNb(y)
let z = Math.floor(intX*intY)
console.log(z);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!