두 길이를 나누고 결과를 정수로 얻는 방법은 무엇입니까?

두 길이를 나누고 결과를 정수로 얻는 방법은 무엇입니까?

두 길이를 나누고 결과를 정수로 얻는 데 문제가 있습니다. 이 패키지를 사용하려고 했습니다.

\usepackage[nomessages]{fp}

그것은 나에게 실제로 효과가 없었습니다. 여러 가지 방법으로 시도했지만 여전히 작동하지 않았습니다.

다른 방법으로 저를 도와주실 수 있나요?

답변1

\numexprand 를 사용할 수 있지만 \dimexpr이는 자르지 않고 반올림됩니다.

\documentclass{article}

\newcommand{\getlengthratio}[2]{%
  \number\numexpr
    \dimexpr#1\relax
     /
    \dimexpr#2\relax
  \relax}

\newcounter{test}

\begin{document}

There are \getlengthratio{\textwidth}{\parindent} parindents in a line

\setcounter{test}{\getlengthratio{\textwidth}{\parindent}}

The same number: \thetest

\end{document}

바닥, 천장, 원형 중에서 선택할 수 있는 다른 접근 방식은 다음과 같습니다 expl3.

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
\DeclareExpandableDocumentCommand{\getlengthratio}{mm}
 {
  \fp_eval:n { floor ( \dim_to_fp:n { #1 } / \dim_to_fp:n { #2 } , 0 ) }
 }
\ExplSyntaxOff

\newcounter{test}

\begin{document}

There are \getlengthratio{\textwidth}{\parindent} parindents in a line

\setcounter{test}{\getlengthratio{\textwidth}{\parindent}}

The same number: \thetest

\end{document}

여기에 이미지 설명을 입력하세요

관련 정보