gpt4 book ai didi

dart - Dart 中的操作 % 返回一个奇怪的值 % 在 Dart 中工作

转载 作者:行者123 更新时间:2023-12-05 02:05:58 29 4
gpt4 key购买 nike

var c 返回 3 但 10/7=1.4285,其余为 0.4285,operator % 有错误?

void main() {
var a = 10;
var b = 7;
var c;
c = a % b;
print(c);
}

最佳答案

来自 % 的文档num 上的接线员在 Dart 中:

Euclidean modulo operator.

Returns the remainder of the Euclidean division. The Euclidean division of two integers a and b yields two integers q and r such that a == b * q + r and 0 <= r < b.abs().

The Euclidean division is only defined for integers, but can be easily extended to work with doubles. In that case r may have a non-integer value, but it still verifies 0 <= r < |b|.

The sign of the returned value r is always positive.

See remainder for the remainder of the truncating division.

https://api.dart.dev/stable/2.8.4/dart-core/num/operator_modulo.html

关于dart - Dart 中的操作 % 返回一个奇怪的值 % 在 Dart 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63053910/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com