Determining if a number is divisible by 1000 [closed]
$begingroup$
I have a number such as:
a = 875952;
And I want to find if it is divisible by 1000.
Is there a concise way of doing that?
functions number-theory
$endgroup$
closed as off-topic by corey979, Michael E2, Daniel Lichtblau, Chris K, m_goldberg Jan 1 at 20:53
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – corey979, Michael E2, Daniel Lichtblau, Chris K, m_goldberg
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
$begingroup$
I have a number such as:
a = 875952;
And I want to find if it is divisible by 1000.
Is there a concise way of doing that?
functions number-theory
$endgroup$
closed as off-topic by corey979, Michael E2, Daniel Lichtblau, Chris K, m_goldberg Jan 1 at 20:53
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – corey979, Michael E2, Daniel Lichtblau, Chris K, m_goldberg
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
$begingroup$
I have a number such as:
a = 875952;
And I want to find if it is divisible by 1000.
Is there a concise way of doing that?
functions number-theory
$endgroup$
I have a number such as:
a = 875952;
And I want to find if it is divisible by 1000.
Is there a concise way of doing that?
functions number-theory
functions number-theory
edited Jan 1 at 14:28
m_goldberg
86.8k872197
86.8k872197
asked Dec 31 '18 at 17:32
user61054user61054
514
514
closed as off-topic by corey979, Michael E2, Daniel Lichtblau, Chris K, m_goldberg Jan 1 at 20:53
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – corey979, Michael E2, Daniel Lichtblau, Chris K, m_goldberg
If this question can be reworded to fit the rules in the help center, please edit the question.
closed as off-topic by corey979, Michael E2, Daniel Lichtblau, Chris K, m_goldberg Jan 1 at 20:53
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – corey979, Michael E2, Daniel Lichtblau, Chris K, m_goldberg
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
Use Divisible
:
Divisible[a, 1000]
False
$endgroup$
add a comment |
$begingroup$
It depends whether you want a three-digit number, in which case try using Mod
, as in:
Mod[a, 1000]
If you want a List
of the digits, then the other solutions above work fine.
If your goal is instead to see whether a
is (evenly) divisible by 1000
, then:
Mod[a,1000] == 0
yields a True
or False
.
Although I don't think this is quite what the OP requests, in response to @TheGreatDuck, here is (inefficient) code that gets the final three digits from any real number:
a = 3454.983745;
Take[
NestWhile[
If[Last[#] == 0, Drop[#, -1]] &, RealDigits[a][[1]],
Last[#] == 0 &], -3]
$endgroup$
$begingroup$
Actually I want to see whether a is divisable by 1000, my ways is to judge the last number of a. But it seems complex. Do you have other ways? thanks.
$endgroup$
– user61054
Dec 31 '18 at 17:49
8
$begingroup$
A recommendation: Always ask your actual question, rather than an intermediate question. You're more likely to get better answers.
$endgroup$
– David G. Stork
Dec 31 '18 at 17:52
$begingroup$
@DavidG.Stork but what if by last 3 digits we mean last 3 digits of even decimal fractions such as 13.535 returning 535 or the list {5,3,5} or any other equivalent representation? Right now your formula gives the last three whole number place values along with the decimal fraction. (And yes, I can see the askers usage/intention was something very different but it would be interesting to see a more precise answer to the original question.)
$endgroup$
– The Great Duck
Dec 31 '18 at 20:16
$begingroup$
@TheGreatDuck: The OP is rather confused about what is desired: "Actually I want to see whether $a$ is divisable by 1000." I tried to answer his actual question. If the OP wants something different, I'm happy to address that.
$endgroup$
– David G. Stork
Dec 31 '18 at 20:18
3
$begingroup$
@TheGreatDuck look up what an x y question is. In this case the best approach would be to edit the original question as it is not the question that the OP wants to be answered.
$endgroup$
– Fogmeister
Jan 1 at 10:24
|
show 2 more comments
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Use Divisible
:
Divisible[a, 1000]
False
$endgroup$
add a comment |
$begingroup$
Use Divisible
:
Divisible[a, 1000]
False
$endgroup$
add a comment |
$begingroup$
Use Divisible
:
Divisible[a, 1000]
False
$endgroup$
Use Divisible
:
Divisible[a, 1000]
False
edited Jan 1 at 16:34
answered Dec 31 '18 at 17:36
kglrkglr
186k10203422
186k10203422
add a comment |
add a comment |
$begingroup$
It depends whether you want a three-digit number, in which case try using Mod
, as in:
Mod[a, 1000]
If you want a List
of the digits, then the other solutions above work fine.
If your goal is instead to see whether a
is (evenly) divisible by 1000
, then:
Mod[a,1000] == 0
yields a True
or False
.
Although I don't think this is quite what the OP requests, in response to @TheGreatDuck, here is (inefficient) code that gets the final three digits from any real number:
a = 3454.983745;
Take[
NestWhile[
If[Last[#] == 0, Drop[#, -1]] &, RealDigits[a][[1]],
Last[#] == 0 &], -3]
$endgroup$
$begingroup$
Actually I want to see whether a is divisable by 1000, my ways is to judge the last number of a. But it seems complex. Do you have other ways? thanks.
$endgroup$
– user61054
Dec 31 '18 at 17:49
8
$begingroup$
A recommendation: Always ask your actual question, rather than an intermediate question. You're more likely to get better answers.
$endgroup$
– David G. Stork
Dec 31 '18 at 17:52
$begingroup$
@DavidG.Stork but what if by last 3 digits we mean last 3 digits of even decimal fractions such as 13.535 returning 535 or the list {5,3,5} or any other equivalent representation? Right now your formula gives the last three whole number place values along with the decimal fraction. (And yes, I can see the askers usage/intention was something very different but it would be interesting to see a more precise answer to the original question.)
$endgroup$
– The Great Duck
Dec 31 '18 at 20:16
$begingroup$
@TheGreatDuck: The OP is rather confused about what is desired: "Actually I want to see whether $a$ is divisable by 1000." I tried to answer his actual question. If the OP wants something different, I'm happy to address that.
$endgroup$
– David G. Stork
Dec 31 '18 at 20:18
3
$begingroup$
@TheGreatDuck look up what an x y question is. In this case the best approach would be to edit the original question as it is not the question that the OP wants to be answered.
$endgroup$
– Fogmeister
Jan 1 at 10:24
|
show 2 more comments
$begingroup$
It depends whether you want a three-digit number, in which case try using Mod
, as in:
Mod[a, 1000]
If you want a List
of the digits, then the other solutions above work fine.
If your goal is instead to see whether a
is (evenly) divisible by 1000
, then:
Mod[a,1000] == 0
yields a True
or False
.
Although I don't think this is quite what the OP requests, in response to @TheGreatDuck, here is (inefficient) code that gets the final three digits from any real number:
a = 3454.983745;
Take[
NestWhile[
If[Last[#] == 0, Drop[#, -1]] &, RealDigits[a][[1]],
Last[#] == 0 &], -3]
$endgroup$
$begingroup$
Actually I want to see whether a is divisable by 1000, my ways is to judge the last number of a. But it seems complex. Do you have other ways? thanks.
$endgroup$
– user61054
Dec 31 '18 at 17:49
8
$begingroup$
A recommendation: Always ask your actual question, rather than an intermediate question. You're more likely to get better answers.
$endgroup$
– David G. Stork
Dec 31 '18 at 17:52
$begingroup$
@DavidG.Stork but what if by last 3 digits we mean last 3 digits of even decimal fractions such as 13.535 returning 535 or the list {5,3,5} or any other equivalent representation? Right now your formula gives the last three whole number place values along with the decimal fraction. (And yes, I can see the askers usage/intention was something very different but it would be interesting to see a more precise answer to the original question.)
$endgroup$
– The Great Duck
Dec 31 '18 at 20:16
$begingroup$
@TheGreatDuck: The OP is rather confused about what is desired: "Actually I want to see whether $a$ is divisable by 1000." I tried to answer his actual question. If the OP wants something different, I'm happy to address that.
$endgroup$
– David G. Stork
Dec 31 '18 at 20:18
3
$begingroup$
@TheGreatDuck look up what an x y question is. In this case the best approach would be to edit the original question as it is not the question that the OP wants to be answered.
$endgroup$
– Fogmeister
Jan 1 at 10:24
|
show 2 more comments
$begingroup$
It depends whether you want a three-digit number, in which case try using Mod
, as in:
Mod[a, 1000]
If you want a List
of the digits, then the other solutions above work fine.
If your goal is instead to see whether a
is (evenly) divisible by 1000
, then:
Mod[a,1000] == 0
yields a True
or False
.
Although I don't think this is quite what the OP requests, in response to @TheGreatDuck, here is (inefficient) code that gets the final three digits from any real number:
a = 3454.983745;
Take[
NestWhile[
If[Last[#] == 0, Drop[#, -1]] &, RealDigits[a][[1]],
Last[#] == 0 &], -3]
$endgroup$
It depends whether you want a three-digit number, in which case try using Mod
, as in:
Mod[a, 1000]
If you want a List
of the digits, then the other solutions above work fine.
If your goal is instead to see whether a
is (evenly) divisible by 1000
, then:
Mod[a,1000] == 0
yields a True
or False
.
Although I don't think this is quite what the OP requests, in response to @TheGreatDuck, here is (inefficient) code that gets the final three digits from any real number:
a = 3454.983745;
Take[
NestWhile[
If[Last[#] == 0, Drop[#, -1]] &, RealDigits[a][[1]],
Last[#] == 0 &], -3]
edited Dec 31 '18 at 21:09
answered Dec 31 '18 at 17:36
David G. StorkDavid G. Stork
24.5k22153
24.5k22153
$begingroup$
Actually I want to see whether a is divisable by 1000, my ways is to judge the last number of a. But it seems complex. Do you have other ways? thanks.
$endgroup$
– user61054
Dec 31 '18 at 17:49
8
$begingroup$
A recommendation: Always ask your actual question, rather than an intermediate question. You're more likely to get better answers.
$endgroup$
– David G. Stork
Dec 31 '18 at 17:52
$begingroup$
@DavidG.Stork but what if by last 3 digits we mean last 3 digits of even decimal fractions such as 13.535 returning 535 or the list {5,3,5} or any other equivalent representation? Right now your formula gives the last three whole number place values along with the decimal fraction. (And yes, I can see the askers usage/intention was something very different but it would be interesting to see a more precise answer to the original question.)
$endgroup$
– The Great Duck
Dec 31 '18 at 20:16
$begingroup$
@TheGreatDuck: The OP is rather confused about what is desired: "Actually I want to see whether $a$ is divisable by 1000." I tried to answer his actual question. If the OP wants something different, I'm happy to address that.
$endgroup$
– David G. Stork
Dec 31 '18 at 20:18
3
$begingroup$
@TheGreatDuck look up what an x y question is. In this case the best approach would be to edit the original question as it is not the question that the OP wants to be answered.
$endgroup$
– Fogmeister
Jan 1 at 10:24
|
show 2 more comments
$begingroup$
Actually I want to see whether a is divisable by 1000, my ways is to judge the last number of a. But it seems complex. Do you have other ways? thanks.
$endgroup$
– user61054
Dec 31 '18 at 17:49
8
$begingroup$
A recommendation: Always ask your actual question, rather than an intermediate question. You're more likely to get better answers.
$endgroup$
– David G. Stork
Dec 31 '18 at 17:52
$begingroup$
@DavidG.Stork but what if by last 3 digits we mean last 3 digits of even decimal fractions such as 13.535 returning 535 or the list {5,3,5} or any other equivalent representation? Right now your formula gives the last three whole number place values along with the decimal fraction. (And yes, I can see the askers usage/intention was something very different but it would be interesting to see a more precise answer to the original question.)
$endgroup$
– The Great Duck
Dec 31 '18 at 20:16
$begingroup$
@TheGreatDuck: The OP is rather confused about what is desired: "Actually I want to see whether $a$ is divisable by 1000." I tried to answer his actual question. If the OP wants something different, I'm happy to address that.
$endgroup$
– David G. Stork
Dec 31 '18 at 20:18
3
$begingroup$
@TheGreatDuck look up what an x y question is. In this case the best approach would be to edit the original question as it is not the question that the OP wants to be answered.
$endgroup$
– Fogmeister
Jan 1 at 10:24
$begingroup$
Actually I want to see whether a is divisable by 1000, my ways is to judge the last number of a. But it seems complex. Do you have other ways? thanks.
$endgroup$
– user61054
Dec 31 '18 at 17:49
$begingroup$
Actually I want to see whether a is divisable by 1000, my ways is to judge the last number of a. But it seems complex. Do you have other ways? thanks.
$endgroup$
– user61054
Dec 31 '18 at 17:49
8
8
$begingroup$
A recommendation: Always ask your actual question, rather than an intermediate question. You're more likely to get better answers.
$endgroup$
– David G. Stork
Dec 31 '18 at 17:52
$begingroup$
A recommendation: Always ask your actual question, rather than an intermediate question. You're more likely to get better answers.
$endgroup$
– David G. Stork
Dec 31 '18 at 17:52
$begingroup$
@DavidG.Stork but what if by last 3 digits we mean last 3 digits of even decimal fractions such as 13.535 returning 535 or the list {5,3,5} or any other equivalent representation? Right now your formula gives the last three whole number place values along with the decimal fraction. (And yes, I can see the askers usage/intention was something very different but it would be interesting to see a more precise answer to the original question.)
$endgroup$
– The Great Duck
Dec 31 '18 at 20:16
$begingroup$
@DavidG.Stork but what if by last 3 digits we mean last 3 digits of even decimal fractions such as 13.535 returning 535 or the list {5,3,5} or any other equivalent representation? Right now your formula gives the last three whole number place values along with the decimal fraction. (And yes, I can see the askers usage/intention was something very different but it would be interesting to see a more precise answer to the original question.)
$endgroup$
– The Great Duck
Dec 31 '18 at 20:16
$begingroup$
@TheGreatDuck: The OP is rather confused about what is desired: "Actually I want to see whether $a$ is divisable by 1000." I tried to answer his actual question. If the OP wants something different, I'm happy to address that.
$endgroup$
– David G. Stork
Dec 31 '18 at 20:18
$begingroup$
@TheGreatDuck: The OP is rather confused about what is desired: "Actually I want to see whether $a$ is divisable by 1000." I tried to answer his actual question. If the OP wants something different, I'm happy to address that.
$endgroup$
– David G. Stork
Dec 31 '18 at 20:18
3
3
$begingroup$
@TheGreatDuck look up what an x y question is. In this case the best approach would be to edit the original question as it is not the question that the OP wants to be answered.
$endgroup$
– Fogmeister
Jan 1 at 10:24
$begingroup$
@TheGreatDuck look up what an x y question is. In this case the best approach would be to edit the original question as it is not the question that the OP wants to be answered.
$endgroup$
– Fogmeister
Jan 1 at 10:24
|
show 2 more comments