D言語で少数第2位で四捨五入
test.d
import std.stdio; import std.math; double round(double val) { return floor(((val * 100) + 5) / 10.0) / 10.0; } void main() { writeln(round(1.45)); writeln(round(1.44)); }
実行
dmd test.d ./test
結果
1.5 1.4
test.d
import std.stdio; import std.math; double round(double val) { return floor(((val * 100) + 5) / 10.0) / 10.0; } void main() { writeln(round(1.45)); writeln(round(1.44)); }
実行
dmd test.d ./test
結果
1.5 1.4