Using writef()
, I can control the output precision of a floating-point number, for example:
writef( "%20.15dr\n", 1.0 / 3.0 ); // 0.333333333333333
but if I use writeln()
for convenience, the number is output with 6 digits:
writeln( 1.0 / 3.0 ); // 0.333333
Is there possibly a way to control the default output precision of floating-point numbers for writeln()
..? (e.g., via some environment variable?)
For comparison, some languages output 15 digits and some 6 digits by default, so the result seems to vary depending on languages (or compilers).
# python2
print 1.0 / 3.0 # 0.333333333333
# python3
print( 1.0 / 3.0 ) # 0.3333333333333333
# julia
println( 1.0 / 3.0 ) # 0.3333333333333333
# gfortran
print *, 1.0d0 / 3.0d0 # 0.33333333333333331
# swift
print( 1.0 / 3.0 ) # 0.333333333333333
# nim
echo( 1.0 / 3.0 ) # 0.3333333333333333
# g++
cout << 1.0 / 3.0 << endl; # 0.333333
# d (dmd)
writeln( 1.0 / 3.0 ); # 0.333333