From 86058fbdca964d294b30e56f771a45211c52c955 Mon Sep 17 00:00:00 2001 From: Juan Jose Comellas Date: Thu, 28 Mar 2013 16:12:05 -0300 Subject: [PATCH] Use io_lib:format/2 instead of float_to_list/1 to display floats Erlang's list_to_float/1 function will use scientific notation and add additional less significant digits to the resulting string due to the internal floating point representation. io_lib:format/2 rounds the values to better match what the user normally expects. e.g. > float_to_list(0.66). "6.60000000000000031086e-01" > io_lib:format("~w", [0.66]). ["0.66"] --- src/getopt.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/getopt.erl b/src/getopt.erl index f9852fb..c2e0d61 100644 --- a/src/getopt.erl +++ b/src/getopt.erl @@ -698,7 +698,7 @@ format_usage_line(_MaxOptionLength, _MaxLineLength, {_OptionLength, OptionText, %% @doc Wrap a text line converting it into several text lines so that the -%% length of each one of them is never over HelpLength characters. +%% length of each one of them is never over Length characters. -spec wrap_text_line(Length :: non_neg_integer(), Text :: string()) -> [string()]. wrap_text_line(Length, Text) -> wrap_text_line(Length, Text, [], 0, []). @@ -730,7 +730,7 @@ default_arg_value_to_string(Value) when is_binary(Value) -> default_arg_value_to_string(Value) when is_integer(Value) -> integer_to_list(Value); default_arg_value_to_string(Value) when is_float(Value) -> - float_to_list(Value); + lists:flatten(io_lib:format("~w", [Value])); default_arg_value_to_string(Value) -> Value.