Skip to content
Snippets Groups Projects
Commit 8221cced authored by Serge Petrenko's avatar Serge Petrenko Committed by Vladimir Davydov
Browse files

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'
...
```
parent e5e23ce2
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment