Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5944571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:33:21+00:00 2026-05-22T16:33:21+00:00

I would like to format my numbers to always display 2 decimal places, rounding

  • 0

I would like to format my numbers to always display 2 decimal places, rounding where applicable.

Examples:

number     display
------     -------
1          1.00
1.341      1.34
1.345      1.35

I have been using this:

parseFloat(num).toFixed(2);

But it’s displaying 1 as 1, rather than 1.00.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:33:22+00:00Added an answer on May 22, 2026 at 4:33 pm
    (Math.round(num * 100) / 100).toFixed(2);
    

    Live Demo

    var num1 = "1";
    document.getElementById('num1').innerHTML = (Math.round(num1 * 100) / 100).toFixed(2);
    
    var num2 = "1.341";
    document.getElementById('num2').innerHTML = (Math.round(num2 * 100) / 100).toFixed(2);
    
    var num3 = "1.345";
    document.getElementById('num3').innerHTML = (Math.round(num3 * 100) / 100).toFixed(2);
    span {
        border: 1px solid #000;
        margin: 5px;
        padding: 5px;
    }
    <span id="num1"></span>
    <span id="num2"></span>
    <span id="num3"></span>

    Note that it will round to 2 decimal places, so the input 1.346 will return 1.35.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a date and I would like to format the date like that:
I would like to rename files numbering: I have a files with '???' format
I would like to format numbers of type double with a German locale in
I would like to rename a large number of columns (column headers) to have
I would like to print floating point numbers in a format like this. 01234.56
I would like to format a float number as a percent-value with JFormattedTextField that
I have a string that occurs in this format: .word 40 I would like
I would like to format numbers, so numbers woul format like this: 1=1 10=10
I hold decimals in a database using DECIMAL(10,5) I would like to format these
I would like to format some commands execution times in a human readable format,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.