Test of integers? Or, round the number if the first two decimal numbers are sufficiently close to 0 or 1?
The following is a MWE, which explains my intention.
documentclass{article}
usepackage{tikz}
usetikzlibrary{math}
begin{document}
tikzmath{
integer = 4/2; decimal = 5/3;
integerB=1/3*3;
}
$integer$ is an integer, and it should be printed as 2.
And $decimal$ is a decimal number, I would like to round it to 1.7.
Another difficulty is that $integerB$ is an integer in fact,
and should be printed as 1.
end{document}
I wonder if it is possible to test a number to determine it is an integer. Alternatively, it would also be great if it is possible to determine whether the first two decimal numbers are sufficiently close to 0 or 1.
tables tikzmath decimal-number
New contributor
add a comment |
The following is a MWE, which explains my intention.
documentclass{article}
usepackage{tikz}
usetikzlibrary{math}
begin{document}
tikzmath{
integer = 4/2; decimal = 5/3;
integerB=1/3*3;
}
$integer$ is an integer, and it should be printed as 2.
And $decimal$ is a decimal number, I would like to round it to 1.7.
Another difficulty is that $integerB$ is an integer in fact,
and should be printed as 1.
end{document}
I wonder if it is possible to test a number to determine it is an integer. Alternatively, it would also be great if it is possible to determine whether the first two decimal numbers are sufficiently close to 0 or 1.
tables tikzmath decimal-number
New contributor
add a comment |
The following is a MWE, which explains my intention.
documentclass{article}
usepackage{tikz}
usetikzlibrary{math}
begin{document}
tikzmath{
integer = 4/2; decimal = 5/3;
integerB=1/3*3;
}
$integer$ is an integer, and it should be printed as 2.
And $decimal$ is a decimal number, I would like to round it to 1.7.
Another difficulty is that $integerB$ is an integer in fact,
and should be printed as 1.
end{document}
I wonder if it is possible to test a number to determine it is an integer. Alternatively, it would also be great if it is possible to determine whether the first two decimal numbers are sufficiently close to 0 or 1.
tables tikzmath decimal-number
New contributor
The following is a MWE, which explains my intention.
documentclass{article}
usepackage{tikz}
usetikzlibrary{math}
begin{document}
tikzmath{
integer = 4/2; decimal = 5/3;
integerB=1/3*3;
}
$integer$ is an integer, and it should be printed as 2.
And $decimal$ is a decimal number, I would like to round it to 1.7.
Another difficulty is that $integerB$ is an integer in fact,
and should be printed as 1.
end{document}
I wonder if it is possible to test a number to determine it is an integer. Alternatively, it would also be great if it is possible to determine whether the first two decimal numbers are sufficiently close to 0 or 1.
tables tikzmath decimal-number
tables tikzmath decimal-number
New contributor
New contributor
edited 1 hour ago
egreg
709k8618823164
709k8618823164
New contributor
asked 1 hour ago
Glenn
211
211
New contributor
New contributor
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
One cannot say from its floating point representation whether the output of an arithmetic operation involving division or non rational operations is actually an integer.
You can consider the l3fp
module of expl3
, available through the package xfp
.
documentclass{article}
usepackage{xfp}
begin{document}
$fpeval{5/3}$ is a decimal number, I would like to round it to
$fpeval{round(5/3,1)}$ or to $fpeval{round(5/3,2)}$
Another difficulty is that $fpeval{(1/3)*3}$ is an integer in fact,
and should be printed as $fpeval{round((1/3)*3,1)}$ or
$fpeval{round((1/3)*3,2)}$.
end{document}
add a comment |
If the accuracy of your numbers is important you might consider farming that out to a computer algebra system (CAS). The sagetex
package relies on the CAS Sage; the documentation can be found on CTAN right here. Documentation on Sage is found here .Sage is not part of the LaTeX distribution (it's big) so it needs to be installed on your computer or, even easier, accessed through a free Cocalc account.
documentclass{article}
usepackage{sagetex}
usepackage{tikz}
usetikzlibrary{math}
begin{document}
begin{sagesilent}
a = 4/2
b = 5/3
c = 1/3*3
end{sagesilent}
$sage{a}$ is an integer, and it should be printed as $sage{a}$.
And $sage{b}$ is not an integer. As a decimal it is approximately
$sage{b.n(digits=6)}$. I would like to round it to $sage{b.n(digits=1)}$.
Another difficulty is that $sage{c}$ is an integer in fact,
and should be printed as $sage{c}$.
end{document}
The output, running in Cocalc, gives:
Notice that Sage interprets your numbers correctly: 4/2 is recognized as 2 and 1/3*3 is recognized as 1. It does need to know the format you want of non integers; but it recognizes that 5/3 is a fraction that can't be reduced and leaves it as a fraction. To force it into a decimal and to specify the number of digits we append .n(digits=6); the documentation is here.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Glenn is a new contributor. Be nice, and check out our Code of Conduct.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f468046%2ftest-of-integers-or-round-the-number-if-the-first-two-decimal-numbers-are-suff%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
One cannot say from its floating point representation whether the output of an arithmetic operation involving division or non rational operations is actually an integer.
You can consider the l3fp
module of expl3
, available through the package xfp
.
documentclass{article}
usepackage{xfp}
begin{document}
$fpeval{5/3}$ is a decimal number, I would like to round it to
$fpeval{round(5/3,1)}$ or to $fpeval{round(5/3,2)}$
Another difficulty is that $fpeval{(1/3)*3}$ is an integer in fact,
and should be printed as $fpeval{round((1/3)*3,1)}$ or
$fpeval{round((1/3)*3,2)}$.
end{document}
add a comment |
One cannot say from its floating point representation whether the output of an arithmetic operation involving division or non rational operations is actually an integer.
You can consider the l3fp
module of expl3
, available through the package xfp
.
documentclass{article}
usepackage{xfp}
begin{document}
$fpeval{5/3}$ is a decimal number, I would like to round it to
$fpeval{round(5/3,1)}$ or to $fpeval{round(5/3,2)}$
Another difficulty is that $fpeval{(1/3)*3}$ is an integer in fact,
and should be printed as $fpeval{round((1/3)*3,1)}$ or
$fpeval{round((1/3)*3,2)}$.
end{document}
add a comment |
One cannot say from its floating point representation whether the output of an arithmetic operation involving division or non rational operations is actually an integer.
You can consider the l3fp
module of expl3
, available through the package xfp
.
documentclass{article}
usepackage{xfp}
begin{document}
$fpeval{5/3}$ is a decimal number, I would like to round it to
$fpeval{round(5/3,1)}$ or to $fpeval{round(5/3,2)}$
Another difficulty is that $fpeval{(1/3)*3}$ is an integer in fact,
and should be printed as $fpeval{round((1/3)*3,1)}$ or
$fpeval{round((1/3)*3,2)}$.
end{document}
One cannot say from its floating point representation whether the output of an arithmetic operation involving division or non rational operations is actually an integer.
You can consider the l3fp
module of expl3
, available through the package xfp
.
documentclass{article}
usepackage{xfp}
begin{document}
$fpeval{5/3}$ is a decimal number, I would like to round it to
$fpeval{round(5/3,1)}$ or to $fpeval{round(5/3,2)}$
Another difficulty is that $fpeval{(1/3)*3}$ is an integer in fact,
and should be printed as $fpeval{round((1/3)*3,1)}$ or
$fpeval{round((1/3)*3,2)}$.
end{document}
answered 1 hour ago
egreg
709k8618823164
709k8618823164
add a comment |
add a comment |
If the accuracy of your numbers is important you might consider farming that out to a computer algebra system (CAS). The sagetex
package relies on the CAS Sage; the documentation can be found on CTAN right here. Documentation on Sage is found here .Sage is not part of the LaTeX distribution (it's big) so it needs to be installed on your computer or, even easier, accessed through a free Cocalc account.
documentclass{article}
usepackage{sagetex}
usepackage{tikz}
usetikzlibrary{math}
begin{document}
begin{sagesilent}
a = 4/2
b = 5/3
c = 1/3*3
end{sagesilent}
$sage{a}$ is an integer, and it should be printed as $sage{a}$.
And $sage{b}$ is not an integer. As a decimal it is approximately
$sage{b.n(digits=6)}$. I would like to round it to $sage{b.n(digits=1)}$.
Another difficulty is that $sage{c}$ is an integer in fact,
and should be printed as $sage{c}$.
end{document}
The output, running in Cocalc, gives:
Notice that Sage interprets your numbers correctly: 4/2 is recognized as 2 and 1/3*3 is recognized as 1. It does need to know the format you want of non integers; but it recognizes that 5/3 is a fraction that can't be reduced and leaves it as a fraction. To force it into a decimal and to specify the number of digits we append .n(digits=6); the documentation is here.
add a comment |
If the accuracy of your numbers is important you might consider farming that out to a computer algebra system (CAS). The sagetex
package relies on the CAS Sage; the documentation can be found on CTAN right here. Documentation on Sage is found here .Sage is not part of the LaTeX distribution (it's big) so it needs to be installed on your computer or, even easier, accessed through a free Cocalc account.
documentclass{article}
usepackage{sagetex}
usepackage{tikz}
usetikzlibrary{math}
begin{document}
begin{sagesilent}
a = 4/2
b = 5/3
c = 1/3*3
end{sagesilent}
$sage{a}$ is an integer, and it should be printed as $sage{a}$.
And $sage{b}$ is not an integer. As a decimal it is approximately
$sage{b.n(digits=6)}$. I would like to round it to $sage{b.n(digits=1)}$.
Another difficulty is that $sage{c}$ is an integer in fact,
and should be printed as $sage{c}$.
end{document}
The output, running in Cocalc, gives:
Notice that Sage interprets your numbers correctly: 4/2 is recognized as 2 and 1/3*3 is recognized as 1. It does need to know the format you want of non integers; but it recognizes that 5/3 is a fraction that can't be reduced and leaves it as a fraction. To force it into a decimal and to specify the number of digits we append .n(digits=6); the documentation is here.
add a comment |
If the accuracy of your numbers is important you might consider farming that out to a computer algebra system (CAS). The sagetex
package relies on the CAS Sage; the documentation can be found on CTAN right here. Documentation on Sage is found here .Sage is not part of the LaTeX distribution (it's big) so it needs to be installed on your computer or, even easier, accessed through a free Cocalc account.
documentclass{article}
usepackage{sagetex}
usepackage{tikz}
usetikzlibrary{math}
begin{document}
begin{sagesilent}
a = 4/2
b = 5/3
c = 1/3*3
end{sagesilent}
$sage{a}$ is an integer, and it should be printed as $sage{a}$.
And $sage{b}$ is not an integer. As a decimal it is approximately
$sage{b.n(digits=6)}$. I would like to round it to $sage{b.n(digits=1)}$.
Another difficulty is that $sage{c}$ is an integer in fact,
and should be printed as $sage{c}$.
end{document}
The output, running in Cocalc, gives:
Notice that Sage interprets your numbers correctly: 4/2 is recognized as 2 and 1/3*3 is recognized as 1. It does need to know the format you want of non integers; but it recognizes that 5/3 is a fraction that can't be reduced and leaves it as a fraction. To force it into a decimal and to specify the number of digits we append .n(digits=6); the documentation is here.
If the accuracy of your numbers is important you might consider farming that out to a computer algebra system (CAS). The sagetex
package relies on the CAS Sage; the documentation can be found on CTAN right here. Documentation on Sage is found here .Sage is not part of the LaTeX distribution (it's big) so it needs to be installed on your computer or, even easier, accessed through a free Cocalc account.
documentclass{article}
usepackage{sagetex}
usepackage{tikz}
usetikzlibrary{math}
begin{document}
begin{sagesilent}
a = 4/2
b = 5/3
c = 1/3*3
end{sagesilent}
$sage{a}$ is an integer, and it should be printed as $sage{a}$.
And $sage{b}$ is not an integer. As a decimal it is approximately
$sage{b.n(digits=6)}$. I would like to round it to $sage{b.n(digits=1)}$.
Another difficulty is that $sage{c}$ is an integer in fact,
and should be printed as $sage{c}$.
end{document}
The output, running in Cocalc, gives:
Notice that Sage interprets your numbers correctly: 4/2 is recognized as 2 and 1/3*3 is recognized as 1. It does need to know the format you want of non integers; but it recognizes that 5/3 is a fraction that can't be reduced and leaves it as a fraction. To force it into a decimal and to specify the number of digits we append .n(digits=6); the documentation is here.
answered 1 hour ago
DJP
7,04421629
7,04421629
add a comment |
add a comment |
Glenn is a new contributor. Be nice, and check out our Code of Conduct.
Glenn is a new contributor. Be nice, and check out our Code of Conduct.
Glenn is a new contributor. Be nice, and check out our Code of Conduct.
Glenn is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f468046%2ftest-of-integers-or-round-the-number-if-the-first-two-decimal-numbers-are-suff%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown