我设置了计数器的值ga
,并想打印涉及其最终值的数字计算结果。
我应该用什么来代替\dots
?
\begin{tikzpicture}[scale=0.7]
\newcounter{ga}
\setcounter{ga}{0}
\tikzmath{\u1 = 10; \x1 =10; }
\draw[double, rounded corners, purple, fill=yellow!3] (0,0) rectangle (\x1+1,\u1+1);
\foreach \u in {1,...,\u1}{
\foreach \x in {1,...,\x1}{
\pgfmathrandominteger{\a}{1}{6}
\pgfmathrandominteger{\b}{1}{6}
\ifthenelse{\a<4 \AND \b<4 \AND \NOT \a =\b}
{\node[blue,draw,circle,font=\scriptsize] at (\x,\u) {sì} \pgfextra{\stepcounter{ga}};}
{\node[font=\scriptsize] at (\x,\u) {no};}
}
}
% \def\gga{\pgfextra{\stepcounter{ga}}}
\pgfmathtruncatemacro{\pr}{\u1*\x1}
%\pgfmathtruncatemacro{\u}{\gga/\pr}
\node[font=\normalsize] at (\x1/2,-1) {$frequenza=\dfrac{\thega}{\pr}= \dots \mbox {\it in forma decimale}$};
\end{tikzpicture}
答案1
你的意思是“如何计算分数以小数形式显示”?
\documentclass{article}
\usepackage{ifthen,tikz,amsmath}
\usetikzlibrary{math}
\newcounter{ga}
\begin{document}
\begin{tikzpicture}[scale=0.7]
\tikzmath{\u1 = 10; \x1 =10; }
\setcounter{ga}{0}
\draw[double, rounded corners, purple, fill=yellow!3] (0,0) rectangle (\x1+1,\u1+1);
\foreach \u in {1,...,\u1}{
\foreach \x in {1,...,\x1}{
\pgfmathrandominteger{\a}{1}{6}
\pgfmathrandominteger{\b}{1}{6}
\ifthenelse{\a<4 \AND \b<4 \AND \NOT \a =\b}
{\node[blue,draw,circle,font=\scriptsize] at (\x,\u) {sì}; \stepcounter{ga}}
{\node[font=\scriptsize] at (\x,\u) {no};}
}
}
\pgfmathtruncatemacro{\pr}{\u1*\x1}
\node[font=\normalsize] at (\x1/2,-1) {%
$\mathit{frequenza}=\dfrac{\thega}{\pr}= \fpeval{\thega/\pr}$ \textit{in forma decimale}%
};
\end{tikzpicture}
\end{document}
您可能需要\fpeval{round(\thega/\pr,2)}
(或者您要求的最大小数位数,而不是 2)。