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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:48:23+00:00 2026-05-30T07:48:23+00:00

I want a function that can take a number (say 1000.43) and return the

  • 0

I want a function that can take a number (say 1000.43) and return the tens, hundreds, thousands, and decimal part. So in 1000.43, it would maybe return an array with [1000, 0, 0, .43]. I know it sounds hard but how would I do that. Maybe you can give me some advice on how to do that or can supply me with the code. Either way is greatly appreciated.

  • 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-30T07:48:25+00:00Added an answer on May 30, 2026 at 7:48 am

    Start with a string to get a consistent picture of your number without further worrying about floating point, which is more complicated than it sounds:

    const toDecimal = (n) => {
        if (!Number.isFinite(n)) {
            throw new RangeError("number must be finite");
        }
    
        // ToString(n) may be of the form …e±…
        let [significand, exponent] = String(n).split("e");
    
        if (exponent === undefined) {
            return significand.includes(".")
                ? significand
                : significand + ".0";
        }
    
        const [integerPart, fractionalPart = ""] = significand.split(".");
        const integerDigits = [...integerPart];
        const fractionalDigits = [...fractionalPart].reverse();
    
        exponent = Number(exponent);
    
        while (exponent > 0) {
            integerDigits.push(fractionalDigits.pop() ?? "0");
            exponent--;
        }
    
        while (exponent < 0) {
            fractionalDigits.push(integerDigits.pop() ?? "0");
            exponent++;
        }
    
        return `${integerDigits.join("") || "0"}.${fractionalDigits.reverse().join("") || "0"}`;
    };
    

    (If you are starting or can start with a decimal string of the right form, you should skip this toDecimal step and just use the string directly.)

    After that, the value of each digit of the integer part can be determined by its position relative to the decimal point (i.e. the end of the integer part).

    const toDigitsAndFractional = (n) => {
        const [integerPart, fractionalPart] = toDecimal(n).split(".");
    
        const result = Array.from(integerPart,
            (c, i) => 10 ** (integerPart.length - i - 1) * Number(c));
    
        result.push("." + fractionalPart);
    
        return result;
    };
    
    const toDecimal = (n) => {
        if (!Number.isFinite(n)) {
            throw new RangeError("number must be finite");
        }
    
        // ToString(n) may be of the form …e±…
        let [significand, exponent] = String(n).split("e");
    
        if (exponent === undefined) {
            return significand.includes(".")
                ? significand
                : significand + ".0";
        }
    
        const [integerPart, fractionalPart = ""] = significand.split(".");
        const integerDigits = [...integerPart];
        const fractionalDigits = [...fractionalPart].reverse();
    
        exponent = Number(exponent);
    
        while (exponent > 0) {
            integerDigits.push(fractionalDigits.pop() ?? "0");
            exponent--;
        }
    
        while (exponent < 0) {
            fractionalDigits.push(integerDigits.pop() ?? "0");
            exponent++;
        }
    
        return `${integerDigits.join("") || "0"}.${fractionalDigits.reverse().join("") || "0"}`;
    };
    
    const toDigitsAndFractional = (n) => {
        const [integerPart, fractionalPart] = toDecimal(n).split(".");
    
        const result = Array.from(integerPart,
            (c, i) => 10 ** (integerPart.length - i - 1) * Number(c));
    
        result.push("." + fractionalPart);
    
        return result;
    };
    
    console.log(JSON.stringify(toDigitsAndFractional(1000.43)));
    console.log(JSON.stringify(toDigitsAndFractional(4314.23)));
    console.log(JSON.stringify(toDigitsAndFractional(1000.43e+20)));
    console.log(JSON.stringify(toDigitsAndFractional(1000.43e-20)));
    .as-console-row-code {
        word-break: break-word;
    }
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a function in python that can take an arbitrary number
I just want a function that can take 2 parameters: the URL to POST
I have a PHP function that requires can take 3 parameteres... I want to
I want to write a jquery function that will take a number of div
Is there any javascript function that can encrypt data: For example i want to
I want to write a function that accepts a parameter which can be either
Say I want a function that takes two floats ( x and y ),
I want to create a function that will take a string and an integer
I am trying to create a simple function that can take a parameter and
I want to implement a String comparison function that doesn't take a different amount

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.