I have the code:
\documentclass[tikz,border=5]{article}
\usepackage{tikz}
\usepackage{xfp}
\usepackage{amsmath}
\usetikzlibrary{math}
\usepackage{fp}
\usetikzlibrary{fixedpointarithmetic}
\begin{document}
\tikzset{fixed point arithmetic}
\tikzmath{
real \x; real \y;
%
\x=-1.3754;
\y = \fpeval{round(\x*5.56,3)};
}
\tikzset{fixed point arithmetic}
\tikzmath{
real \z; real \w;
%
\z=1.3754;
\w = \fpeval{round(\z*5.56,3)};
}
\vspace{3cm}
O valor de $x$ é: \fpeval{round(\x,3)} \\
O valor de $y$ é: \y \\
O valor de $z$ é: \fpeval{round(\z,3)} \\
O valor de $w$ é: \w \\
\end{document}
whose output is the following:
When I operate negative numbers in tikzmath
, the decimal places of the result is incontrolable. However when the calculation deal with positive real numbers, I set the decimal places with \fpeval{round(x,3)}
(to three decimal places) and I can to control the precision.
My question is how can I fix this? Why fixed point arithmetic
is noisy with negative numbers? I would to set the decimal places in the tikzmath
code space, not in the text.
Many thanks!
O valor de $y$ é: \fpeval{round(\y,3)}
works. No idea whyround()
to print number to X decimal places feel absolutely like the wrong way.-7.647 == -7.6470000000000
. What you want is to print the number to 3 decimal places.pgfmathprintnumber
, which works in this case.