decimal: add methods trim and rescale
This patch adds 2 methods to decimal library and lua module: trim will remove all trailing fractional zeros and rescale will either perform rounding or append excess fractional zeros. Closes #4372 @TarantoolBot document Title: document 2 new functions in decimal Lua module 2 new functions are added to the decimal module: `decimal.trim()` and `decimal.rescale()` `decimal.trim()` removes any trailing fractional zeros from the number: ``` tarantool> a = dec.new('123.45570000') --- ... tarantool> decimal.trim(a) --- - '123.4557' ... ``` `decimal.rescale()` will round the number to a given scale, if it is less than the number scale. Otherwise it will append trailing fractional zeros, so that the resulting number scale will be the same as the given one. ``` tarantool> a = dec.new(123.45) --- ... tarantool> dec.rescale(a,1) --- - '123.5' ... tarantool> dec.rescale(a, 4) --- - '123.4500' ... ```
Showing
- src/lib/core/decimal.c 28 additions, 0 deletionssrc/lib/core/decimal.c
- src/lib/core/decimal.h 19 additions, 0 deletionssrc/lib/core/decimal.h
- src/lua/decimal.c 36 additions, 0 deletionssrc/lua/decimal.c
- test/app/decimal.result 52 additions, 0 deletionstest/app/decimal.result
- test/app/decimal.test.lua 15 additions, 0 deletionstest/app/decimal.test.lua
Loading
Please register or sign in to comment