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 7828539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:23:32+00:00 2026-06-02T10:23:32+00:00

I would love to be able to move a decimal point 2 places across

  • 0

I would love to be able to move a decimal point 2 places across an unknown amount of numbers without using math. I know that seems weird, but finite precision causes some shifts. My javascript is not strong, but I’d really like to learn how to chop up a number and do this if it’s possible. So, I’m hoping you awesome folks can help.

The problem:

  • 575/960 = 0.5989583333333334 using the console
  • I would like to make that a copy and pastable percentage like: 59.89583333333334%
  • If I use math and multiply by 100, it returns 59.895833333333336 because of finite precision

Is there a way to make that a string and just always move the decimal 2 places to the right to skip the math?

Here’s a fiddle too, with the codes: http://jsfiddle.net/dandenney/W9fXz/

If you want to know why I need it and want the precision, it’s for this little tool that I made for getting responsive percentages without using the calculator: http://responsv.com/flexible-math

  • 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-06-02T10:23:36+00:00Added an answer on June 2, 2026 at 10:23 am

    If the original number is of this type of known structure and always has at least two digits to the right of the decimal, you can do it like this:

    function makePercentStr(num) {
        var numStr = num + "";
        // if no decimal point, add .00 on end
        if (numStr.indexOf(".") == -1) {
            numStr += ".00";
        } else {
            // make sure there's at least two chars after decimal point
            while (!numStr.match(/\.../)) {
                numStr += "0";        
            }
        }
        return(numStr.replace(/\.(..)/, "$1.")
               .replace(/^0+/, "")    // trim leading zeroes
               .replace(/\.$/, "")    // trim trailing decimals
               .replace(/^$/, "0")    // if empty, add back a single 0
               + "%");
    }
    

    Working demo with test cases: http://jsfiddle.net/jfriend00/ZRNuw/

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

Sidebar

Related Questions

I would love to be able to do >>> A = numpy.array(((1,2),(3,4))) >>> idx
In Magento I'm creating a custom module and would love to be able to
my designer passed me a look that I would love to be able to
I would love to sort an embedded MongoDB object using PHP Lithium. I have
I often use c-t-$char change-till-character and d-t-$char and would love to be able to
I have a little app here, and I would love to be able to
I would love to be able to use a regular MouseBinding to capture a
I am just learning scheme, but I would love to be able to repeat
). I would love to be able to do that. I got a rather
I would love to be able to test java code with rspec under jruby,

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.