This commit is contained in:
anlicheng 2023-07-27 16:32:13 +08:00
parent cfe88b4975
commit 4c0d8bee31
2 changed files with 12 additions and 4 deletions

View File

@ -38,8 +38,9 @@ normalized(#point{measurement = Name, tags = Tags, fields = Fields, time = Time}
field_val(V) when is_integer(V) ->
<<(integer_to_binary(V))/binary, "i">>;
field_val(V) when is_number(V) ->
<<(integer_to_binary(V))/binary, "u">>;
field_val(V) when is_float(V) ->
%%
iot_util:float_to_binary(V, 6);
field_val(V) when is_binary(V) ->
<<$", V/binary, $">>;
field_val(V) when is_list(V); is_map(V) ->

View File

@ -10,7 +10,7 @@
-author("licheng5").
%% API
-export([timestamp/0, number_format/2, current_time/0, timestamp_of_seconds/0]).
-export([timestamp/0, number_format/2, current_time/0, timestamp_of_seconds/0, float_to_binary/2]).
-export([step/3, chunks/2, rand_bytes/1, uuid/0, md5/1, parse_mapper/1]).
-export([json_data/1, json_error/2]).
-export([queue_limited_in/3, assert_call/2]).
@ -115,3 +115,10 @@ parse_mapper(Mapper) when is_list(Mapper) ->
false ->
error
end.
-spec float_to_binary(Num :: number(), integer()) -> binary().
float_to_binary(V, _) when is_integer(V) ->
integer_to_binary(V);
float_to_binary(V, Decimals) when is_float(V), is_integer(Decimals) ->
S = float_to_list(V, [{decimals, Decimals}, compact]),
list_to_binary(S).