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

213
Views
Convert string to number but maintain zeros in Javascript

I am working with GBP currency in Javascript and converting a string currency to a number like the following: Number('1.20') will give me 1.2. But I want to maintain the 0 when converting to a number type. Is this possible? This is the result that I want : 1.20. Can anyone help me please?

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

0

You can control the decimals like this in Javascript:

let num = 1.204;
let n = num.toFixed(2)
about 4 years ago · Juan Pablo Isaza Report

0

A better way to work with Currency in Javascript is to use the Intl.NumberFormat. For course, the output will be of the type: 'String'

The output will take care of the number of decimal places depending on the Currency you specify. In your case GBP so it will be 2 decimal places.

Example:

const number = 1.2;
console.log(new Intl.NumberFormat('en', { style: 'currency', currency: 'GBP' }).format(number));

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!