Multiply a number so that it's always in the thousand billions
Clash 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.
multiple-integral
add a comment |Â
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.
multiple-integral
add a comment |Â
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.
multiple-integral
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.
multiple-integral
edited Jul 19 at 6:29
asked Jul 19 at 5:52


James Hay
1084
1084
add a comment |Â
add a comment |Â
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)$.
Thanks, going to give this one a go. All x are integers so I won't be needing thefloor
– 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
add a comment |Â
up vote
0
down vote
Pick a number $k$ between one thousand billion and ten thousand billion and take $y = frackx$ ?
If you look at the examples, the OP wants $y$ to be a power of $10$.
– Arnaud Mortier
Jul 19 at 6:09
add a comment |Â
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.
add a comment |Â
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)$.
Thanks, going to give this one a go. All x are integers so I won't be needing thefloor
– 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
add a comment |Â
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)$.
Thanks, going to give this one a go. All x are integers so I won't be needing thefloor
– 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
add a comment |Â
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)$.
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)$.
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 thefloor
– 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
add a comment |Â
Thanks, going to give this one a go. All x are integers so I won't be needing thefloor
– 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
add a comment |Â
up vote
0
down vote
Pick a number $k$ between one thousand billion and ten thousand billion and take $y = frackx$ ?
If you look at the examples, the OP wants $y$ to be a power of $10$.
– Arnaud Mortier
Jul 19 at 6:09
add a comment |Â
up vote
0
down vote
Pick a number $k$ between one thousand billion and ten thousand billion and take $y = frackx$ ?
If you look at the examples, the OP wants $y$ to be a power of $10$.
– Arnaud Mortier
Jul 19 at 6:09
add a comment |Â
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$ ?
Pick a number $k$ between one thousand billion and ten thousand billion and take $y = frackx$ ?
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
add a comment |Â
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
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
answered Jul 19 at 6:01
Piyush Divyanakar
3,258122
3,258122
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password