diff --git a/src/FileFormats/NL/NL.jl b/src/FileFormats/NL/NL.jl index d361e3f75d..5c957be11b 100644 --- a/src/FileFormats/NL/NL.jl +++ b/src/FileFormats/NL/NL.jl @@ -508,7 +508,12 @@ function _process_constraint( return end -_str(x::Float64) = isinteger(x) ? string(round(Int, x)) : string(x) +function _str(x::Float64) + if isinteger(x) && (typemin(Int) <= x <= typemax(Int)) + return string(round(Int, x)) + end + return string(x) +end _write_term(io, x::Float64, ::Any) = println(io, "n", _str(x)) _write_term(io, x::Int, ::Any) = println(io, "o", x) diff --git a/test/FileFormats/NL/NL.jl b/test/FileFormats/NL/NL.jl index 24b37e1ea2..c20a25571b 100644 --- a/test/FileFormats/NL/NL.jl +++ b/test/FileFormats/NL/NL.jl @@ -1014,6 +1014,14 @@ function test_moi() return end +function test_float_rounding() + @test NL._str(1.0) == "1" + @test NL._str(1.2) == "1.2" + @test NL._str(1e50) == "1.0e50" + @test NL._str(-1e50) == "-1.0e50" + return +end + function runtests() for name in names(@__MODULE__; all = true) if startswith("$(name)", "test_")