From c899626954594412f0f749b6914d5ffec7c70697 Mon Sep 17 00:00:00 2001 From: anlicheng Date: Wed, 9 Aug 2023 11:18:48 +0800 Subject: [PATCH] fix --- apps/iot/src/iot_util.erl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/iot/src/iot_util.erl b/apps/iot/src/iot_util.erl index 519b4d6..f5f01ac 100644 --- a/apps/iot/src/iot_util.erl +++ b/apps/iot/src/iot_util.erl @@ -10,7 +10,7 @@ -author("licheng5"). %% API --export([timestamp/0, number_format/2, current_time/0, timestamp_of_seconds/0, float_to_binary/2]). +-export([timestamp/0, number_format/2, current_time/0, timestamp_of_seconds/0, float_to_binary/2, int_format/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]). @@ -33,6 +33,15 @@ number_format(Num, _Decimals) when is_integer(Num) -> number_format(Float, Decimals) when is_float(Float) -> list_to_float(float_to_list(Float, [{decimals, Decimals}, compact])). +int_format(Num, Len) when is_integer(Num), Len > 0 -> + S = integer_to_list(Num), + case length(S) > Len of + true -> + list_to_integer(lists:sublist(S, 1, Len)); + false -> + Num + end. + step(Start, End, Step) when is_integer(Start), is_integer(End), is_integer(Step), Start < End, Step > 0 -> step(Start, End, Step, []). step(Start, End, Step, Acc) when Start < End ->