Multiply a number so that it's always in the thousand billions

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












Excuse my lack of mathematical notation, hopefully this makes sense.



Say I have a number which is x



10,000,000,000,000 > x > 999,999,999



I always want to multiply this number by some other number y, so that the result z in the thousand billions, so for example:



x = 1,230,000,000 
x * y = z
z = 1,230,000,000,000
y = 1000

x = 55,123,000,000
x * y = z
z = 5,512,300,000,000
y = 100

x = 456,123,000,000
x * y = z
z = 4,561,230,000,000
y = 10

x = 7,894,560,000,000
x * y = z
z = 7,894,560,000,000
y = 1


All I have is x and the I know that x is be between 1,000,000,000 and 9,999,999,999,999.



How can I find the value of y so that I can calculate z? I'm currently doing this manually (in code) with if statements,



if x < 10 => x * 1000
if x < 100 => x * 100
if x < 1000 => x * 10
if x < 1000 => x


But I'm looking for a single mathematical function that can do this for me.



Solved with Arnaud Mortier's answer



Using the marked answer I created the function (in Javascript)



const fn = x => 
let k = 12 - Math.floor(Math.log10(x));
let y = Math.pow(10, k);
let z = x * y;

console.log(`x = $x, k = $k, y = $y, z = $z`);

return z;
;


Even more than I hoped for, this works for any positive integer, not just those in my range.







share|cite|improve this question

























    up vote
    1
    down vote

    favorite












    Excuse my lack of mathematical notation, hopefully this makes sense.



    Say I have a number which is x



    10,000,000,000,000 > x > 999,999,999



    I always want to multiply this number by some other number y, so that the result z in the thousand billions, so for example:



    x = 1,230,000,000 
    x * y = z
    z = 1,230,000,000,000
    y = 1000

    x = 55,123,000,000
    x * y = z
    z = 5,512,300,000,000
    y = 100

    x = 456,123,000,000
    x * y = z
    z = 4,561,230,000,000
    y = 10

    x = 7,894,560,000,000
    x * y = z
    z = 7,894,560,000,000
    y = 1


    All I have is x and the I know that x is be between 1,000,000,000 and 9,999,999,999,999.



    How can I find the value of y so that I can calculate z? I'm currently doing this manually (in code) with if statements,



    if x < 10 => x * 1000
    if x < 100 => x * 100
    if x < 1000 => x * 10
    if x < 1000 => x


    But I'm looking for a single mathematical function that can do this for me.



    Solved with Arnaud Mortier's answer



    Using the marked answer I created the function (in Javascript)



    const fn = x => 
    let k = 12 - Math.floor(Math.log10(x));
    let y = Math.pow(10, k);
    let z = x * y;

    console.log(`x = $x, k = $k, y = $y, z = $z`);

    return z;
    ;


    Even more than I hoped for, this works for any positive integer, not just those in my range.







    share|cite|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Excuse my lack of mathematical notation, hopefully this makes sense.



      Say I have a number which is x



      10,000,000,000,000 > x > 999,999,999



      I always want to multiply this number by some other number y, so that the result z in the thousand billions, so for example:



      x = 1,230,000,000 
      x * y = z
      z = 1,230,000,000,000
      y = 1000

      x = 55,123,000,000
      x * y = z
      z = 5,512,300,000,000
      y = 100

      x = 456,123,000,000
      x * y = z
      z = 4,561,230,000,000
      y = 10

      x = 7,894,560,000,000
      x * y = z
      z = 7,894,560,000,000
      y = 1


      All I have is x and the I know that x is be between 1,000,000,000 and 9,999,999,999,999.



      How can I find the value of y so that I can calculate z? I'm currently doing this manually (in code) with if statements,



      if x < 10 => x * 1000
      if x < 100 => x * 100
      if x < 1000 => x * 10
      if x < 1000 => x


      But I'm looking for a single mathematical function that can do this for me.



      Solved with Arnaud Mortier's answer



      Using the marked answer I created the function (in Javascript)



      const fn = x => 
      let k = 12 - Math.floor(Math.log10(x));
      let y = Math.pow(10, k);
      let z = x * y;

      console.log(`x = $x, k = $k, y = $y, z = $z`);

      return z;
      ;


      Even more than I hoped for, this works for any positive integer, not just those in my range.







      share|cite|improve this question













      Excuse my lack of mathematical notation, hopefully this makes sense.



      Say I have a number which is x



      10,000,000,000,000 > x > 999,999,999



      I always want to multiply this number by some other number y, so that the result z in the thousand billions, so for example:



      x = 1,230,000,000 
      x * y = z
      z = 1,230,000,000,000
      y = 1000

      x = 55,123,000,000
      x * y = z
      z = 5,512,300,000,000
      y = 100

      x = 456,123,000,000
      x * y = z
      z = 4,561,230,000,000
      y = 10

      x = 7,894,560,000,000
      x * y = z
      z = 7,894,560,000,000
      y = 1


      All I have is x and the I know that x is be between 1,000,000,000 and 9,999,999,999,999.



      How can I find the value of y so that I can calculate z? I'm currently doing this manually (in code) with if statements,



      if x < 10 => x * 1000
      if x < 100 => x * 100
      if x < 1000 => x * 10
      if x < 1000 => x


      But I'm looking for a single mathematical function that can do this for me.



      Solved with Arnaud Mortier's answer



      Using the marked answer I created the function (in Javascript)



      const fn = x => 
      let k = 12 - Math.floor(Math.log10(x));
      let y = Math.pow(10, k);
      let z = x * y;

      console.log(`x = $x, k = $k, y = $y, z = $z`);

      return z;
      ;


      Even more than I hoped for, this works for any positive integer, not just those in my range.









      share|cite|improve this question












      share|cite|improve this question




      share|cite|improve this question








      edited Jul 19 at 6:29
























      asked Jul 19 at 5:52









      James Hay

      1084




      1084




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Set $y=10^k$. beginalign10^12leq z<10^13&Longleftrightarrow 12leq log_10(xcdot 10^k)<13\&Longleftrightarrow leftlfloor log_10(xcdot 10^k)rightrfloor=12\&Longleftrightarrow leftlfloor log_10(x)+krightrfloor=12\&Longleftrightarrow k=12-leftlfloor log_10(x)rightrfloor\endalign



          If you don't have $log_10$ implemented in your computer, use $log_10(x)=fracln(x)ln(10)$.



          The function $leftlfloor xrightrfloor$ is usually implemented as $operatornamefloor(x)$.






          share|cite|improve this answer





















          • Thanks, going to give this one a go. All x are integers so I won't be needing the floor
            – James Hay
            Jul 19 at 6:09










          • @JamesHay You will most likely need the floor function after you apply log.
            – Arnaud Mortier
            Jul 19 at 6:09










          • Oh my god, that completely worked! Thanks heaps.
            – James Hay
            Jul 19 at 6:18










          • @JamesHay You're welcome.
            – Arnaud Mortier
            Jul 19 at 6:19

















          up vote
          0
          down vote













          Pick a number $k$ between one thousand billion and ten thousand billion and take $y = frackx$ ?






          share|cite|improve this answer





















          • If you look at the examples, the OP wants $y$ to be a power of $10$.
            – Arnaud Mortier
            Jul 19 at 6:09

















          up vote
          0
          down vote













          Writing $x$ in scientific notation we get something like $ktimes10^n$ where $1<k<9$. For example $x = 1,230,000,000 = 1.23times10^9$ Now you want the $z = 1,230,000,000,000=1.23times10^12$. So you need to multiply $1000$ or $10^3$. Just find the value $n$ when $x$ is written in scientific notation and if see how much you are short of $12$. And multiply that much.






          share|cite|improve this answer





















            Your Answer




            StackExchange.ifUsing("editor", function ()
            return StackExchange.using("mathjaxEditing", function ()
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            );
            );
            , "mathjax-editing");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "69"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            noCode: true, onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );








             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2856304%2fmultiply-a-number-so-that-its-always-in-the-thousand-billions%23new-answer', 'question_page');

            );

            Post as a guest






























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            Set $y=10^k$. beginalign10^12leq z<10^13&Longleftrightarrow 12leq log_10(xcdot 10^k)<13\&Longleftrightarrow leftlfloor log_10(xcdot 10^k)rightrfloor=12\&Longleftrightarrow leftlfloor log_10(x)+krightrfloor=12\&Longleftrightarrow k=12-leftlfloor log_10(x)rightrfloor\endalign



            If you don't have $log_10$ implemented in your computer, use $log_10(x)=fracln(x)ln(10)$.



            The function $leftlfloor xrightrfloor$ is usually implemented as $operatornamefloor(x)$.






            share|cite|improve this answer





















            • Thanks, going to give this one a go. All x are integers so I won't be needing the floor
              – James Hay
              Jul 19 at 6:09










            • @JamesHay You will most likely need the floor function after you apply log.
              – Arnaud Mortier
              Jul 19 at 6:09










            • Oh my god, that completely worked! Thanks heaps.
              – James Hay
              Jul 19 at 6:18










            • @JamesHay You're welcome.
              – Arnaud Mortier
              Jul 19 at 6:19














            up vote
            1
            down vote



            accepted










            Set $y=10^k$. beginalign10^12leq z<10^13&Longleftrightarrow 12leq log_10(xcdot 10^k)<13\&Longleftrightarrow leftlfloor log_10(xcdot 10^k)rightrfloor=12\&Longleftrightarrow leftlfloor log_10(x)+krightrfloor=12\&Longleftrightarrow k=12-leftlfloor log_10(x)rightrfloor\endalign



            If you don't have $log_10$ implemented in your computer, use $log_10(x)=fracln(x)ln(10)$.



            The function $leftlfloor xrightrfloor$ is usually implemented as $operatornamefloor(x)$.






            share|cite|improve this answer





















            • Thanks, going to give this one a go. All x are integers so I won't be needing the floor
              – James Hay
              Jul 19 at 6:09










            • @JamesHay You will most likely need the floor function after you apply log.
              – Arnaud Mortier
              Jul 19 at 6:09










            • Oh my god, that completely worked! Thanks heaps.
              – James Hay
              Jul 19 at 6:18










            • @JamesHay You're welcome.
              – Arnaud Mortier
              Jul 19 at 6:19












            up vote
            1
            down vote



            accepted







            up vote
            1
            down vote



            accepted






            Set $y=10^k$. beginalign10^12leq z<10^13&Longleftrightarrow 12leq log_10(xcdot 10^k)<13\&Longleftrightarrow leftlfloor log_10(xcdot 10^k)rightrfloor=12\&Longleftrightarrow leftlfloor log_10(x)+krightrfloor=12\&Longleftrightarrow k=12-leftlfloor log_10(x)rightrfloor\endalign



            If you don't have $log_10$ implemented in your computer, use $log_10(x)=fracln(x)ln(10)$.



            The function $leftlfloor xrightrfloor$ is usually implemented as $operatornamefloor(x)$.






            share|cite|improve this answer













            Set $y=10^k$. beginalign10^12leq z<10^13&Longleftrightarrow 12leq log_10(xcdot 10^k)<13\&Longleftrightarrow leftlfloor log_10(xcdot 10^k)rightrfloor=12\&Longleftrightarrow leftlfloor log_10(x)+krightrfloor=12\&Longleftrightarrow k=12-leftlfloor log_10(x)rightrfloor\endalign



            If you don't have $log_10$ implemented in your computer, use $log_10(x)=fracln(x)ln(10)$.



            The function $leftlfloor xrightrfloor$ is usually implemented as $operatornamefloor(x)$.







            share|cite|improve this answer













            share|cite|improve this answer



            share|cite|improve this answer











            answered Jul 19 at 6:06









            Arnaud Mortier

            19k22159




            19k22159











            • Thanks, going to give this one a go. All x are integers so I won't be needing the floor
              – James Hay
              Jul 19 at 6:09










            • @JamesHay You will most likely need the floor function after you apply log.
              – Arnaud Mortier
              Jul 19 at 6:09










            • Oh my god, that completely worked! Thanks heaps.
              – James Hay
              Jul 19 at 6:18










            • @JamesHay You're welcome.
              – Arnaud Mortier
              Jul 19 at 6:19
















            • Thanks, going to give this one a go. All x are integers so I won't be needing the floor
              – James Hay
              Jul 19 at 6:09










            • @JamesHay You will most likely need the floor function after you apply log.
              – Arnaud Mortier
              Jul 19 at 6:09










            • Oh my god, that completely worked! Thanks heaps.
              – James Hay
              Jul 19 at 6:18










            • @JamesHay You're welcome.
              – Arnaud Mortier
              Jul 19 at 6:19















            Thanks, going to give this one a go. All x are integers so I won't be needing the floor
            – James Hay
            Jul 19 at 6:09




            Thanks, going to give this one a go. All x are integers so I won't be needing the floor
            – James Hay
            Jul 19 at 6:09












            @JamesHay You will most likely need the floor function after you apply log.
            – Arnaud Mortier
            Jul 19 at 6:09




            @JamesHay You will most likely need the floor function after you apply log.
            – Arnaud Mortier
            Jul 19 at 6:09












            Oh my god, that completely worked! Thanks heaps.
            – James Hay
            Jul 19 at 6:18




            Oh my god, that completely worked! Thanks heaps.
            – James Hay
            Jul 19 at 6:18












            @JamesHay You're welcome.
            – Arnaud Mortier
            Jul 19 at 6:19




            @JamesHay You're welcome.
            – Arnaud Mortier
            Jul 19 at 6:19










            up vote
            0
            down vote













            Pick a number $k$ between one thousand billion and ten thousand billion and take $y = frackx$ ?






            share|cite|improve this answer





















            • If you look at the examples, the OP wants $y$ to be a power of $10$.
              – Arnaud Mortier
              Jul 19 at 6:09














            up vote
            0
            down vote













            Pick a number $k$ between one thousand billion and ten thousand billion and take $y = frackx$ ?






            share|cite|improve this answer





















            • If you look at the examples, the OP wants $y$ to be a power of $10$.
              – Arnaud Mortier
              Jul 19 at 6:09












            up vote
            0
            down vote










            up vote
            0
            down vote









            Pick a number $k$ between one thousand billion and ten thousand billion and take $y = frackx$ ?






            share|cite|improve this answer













            Pick a number $k$ between one thousand billion and ten thousand billion and take $y = frackx$ ?







            share|cite|improve this answer













            share|cite|improve this answer



            share|cite|improve this answer











            answered Jul 19 at 6:01









            Daniel Pietrobon

            3,26421836




            3,26421836











            • If you look at the examples, the OP wants $y$ to be a power of $10$.
              – Arnaud Mortier
              Jul 19 at 6:09
















            • If you look at the examples, the OP wants $y$ to be a power of $10$.
              – Arnaud Mortier
              Jul 19 at 6:09















            If you look at the examples, the OP wants $y$ to be a power of $10$.
            – Arnaud Mortier
            Jul 19 at 6:09




            If you look at the examples, the OP wants $y$ to be a power of $10$.
            – Arnaud Mortier
            Jul 19 at 6:09










            up vote
            0
            down vote













            Writing $x$ in scientific notation we get something like $ktimes10^n$ where $1<k<9$. For example $x = 1,230,000,000 = 1.23times10^9$ Now you want the $z = 1,230,000,000,000=1.23times10^12$. So you need to multiply $1000$ or $10^3$. Just find the value $n$ when $x$ is written in scientific notation and if see how much you are short of $12$. And multiply that much.






            share|cite|improve this answer

























              up vote
              0
              down vote













              Writing $x$ in scientific notation we get something like $ktimes10^n$ where $1<k<9$. For example $x = 1,230,000,000 = 1.23times10^9$ Now you want the $z = 1,230,000,000,000=1.23times10^12$. So you need to multiply $1000$ or $10^3$. Just find the value $n$ when $x$ is written in scientific notation and if see how much you are short of $12$. And multiply that much.






              share|cite|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Writing $x$ in scientific notation we get something like $ktimes10^n$ where $1<k<9$. For example $x = 1,230,000,000 = 1.23times10^9$ Now you want the $z = 1,230,000,000,000=1.23times10^12$. So you need to multiply $1000$ or $10^3$. Just find the value $n$ when $x$ is written in scientific notation and if see how much you are short of $12$. And multiply that much.






                share|cite|improve this answer













                Writing $x$ in scientific notation we get something like $ktimes10^n$ where $1<k<9$. For example $x = 1,230,000,000 = 1.23times10^9$ Now you want the $z = 1,230,000,000,000=1.23times10^12$. So you need to multiply $1000$ or $10^3$. Just find the value $n$ when $x$ is written in scientific notation and if see how much you are short of $12$. And multiply that much.







                share|cite|improve this answer













                share|cite|improve this answer



                share|cite|improve this answer











                answered Jul 19 at 6:01









                Piyush Divyanakar

                3,258122




                3,258122






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2856304%2fmultiply-a-number-so-that-its-always-in-the-thousand-billions%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What is the equation of a 3D cone with generalised tilt?

                    Color the edges and diagonals of a regular polygon

                    Relationship between determinant of matrix and determinant of adjoint?