라이브러리

[PHP] BcMathNumber::mod - 임의 정밀도 숫자의 모듈러스를 가져옵니다.




BcMathNumber::mod

PHP의 `BcMath` 클래스는 부동소수점 연산을 위한 고정소수점 수를 제공합니다. `BcMathNumber::mod` 메서드는 두 개의 부동소수점 수의 나머지를 계산하는 데 사용됩니다.

사용법

`BcMathNumber::mod` 메서드는 두 개의 부동소수점 수를 인수로 받습니다. 첫 번째 인수는 나눗셈의 분모, 두 번째 인수는 나눗셈의 분자입니다.

#hostingforum.kr
php

BcMathNumber::mod($dividend, $divisor)



예제

#hostingforum.kr
php

// BcMathNumber::mod 예제

$bc = new BcMath();

$dividend = $bc->create('10.5');

$divisor = $bc->create('3.2');



$result = $dividend->mod($divisor);

echo $result; // 1.3



주의사항

`BcMathNumber::mod` 메서드는 두 개의 부동소수점 수를 인수로 받습니다. 첫 번째 인수는 나눗셈의 분모, 두 번째 인수는 나눗셈의 분자입니다. 두 수를 나눈 나머지를 반환합니다.

예외

`BcMathNumber::mod` 메서드는 다음과 같은 예외를 발생시킬 수 있습니다.

* `DivisionByZeroException`: 나눗셈의 분모가 0인 경우
* `InvalidArgumentTypeException`: 인수가 부동소수점 수가 아닌 경우

예제

#hostingforum.kr
php

// BcMathNumber::mod 예외 예제

$bc = new BcMath();

$dividend = $bc->create('10.5');

$divisor = $bc->create('0');



try {

    $result = $dividend->mod($divisor);

} catch (DivisionByZeroException $e) {

    echo '나눗셈의 분모는 0일 수 없습니다.';

}



결론

`BcMathNumber::mod` 메서드는 두 개의 부동소수점 수의 나머지를 계산하는 데 사용됩니다. 이 메서드는 두 수를 나눈 나머지를 반환합니다. 그러나 나눗셈의 분모가 0인 경우 `DivisionByZeroException` 예외를 발생시킵니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 8,985건 / 592 페이지

검색

게시물 검색