mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-22 04:20:50 +01:00
extend readme to highlight special cases around parsing and printing when using trailing zeros
This commit is contained in:
parent
fa3b22f4d4
commit
49883997d8
1 changed files with 28 additions and 0 deletions
28
README.md
28
README.md
|
@ -6,6 +6,8 @@ Arbitrary-precision fixed-point decimal numbers in go.
|
||||||
|
|
||||||
_Note:_ Decimal library can "only" represent numbers with a maximum of 2^31 digits after the decimal point.
|
_Note:_ Decimal library can "only" represent numbers with a maximum of 2^31 digits after the decimal point.
|
||||||
|
|
||||||
|
_Note:_ The library does not remove trailing zeros when parsing decimals from strings, e.g., `1.18` does not internally equal `1.1800` when parsing with this library, see example in usage
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
* The zero-value is 0, and is safe to use without initialization
|
* The zero-value is 0, and is safe to use without initialization
|
||||||
|
@ -57,6 +59,32 @@ func main() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Conservation of precision with trailing zeros. This conservation is, however,
|
||||||
|
not translated backwards when printing the decimal as string.
|
||||||
|
|
||||||
|
This is important to know.
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
noZeros := "1.18"
|
||||||
|
trailingZeros := "1.1800"
|
||||||
|
|
||||||
|
d1 := decimal.RequireFromString(noZeros)
|
||||||
|
d2 := decimal.RequireFromString(trailingZeros)
|
||||||
|
|
||||||
|
fmt.Println(d1.Coefficient(), d1.Exponent()) // 118 -2
|
||||||
|
fmt.Println(d2.Coefficient(), d2.Exponent()) // 118 -4
|
||||||
|
fmt.Println(d1) // 1.18
|
||||||
|
fmt.Println(d2) // 1.18
|
||||||
|
```
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
http://godoc.org/github.com/shopspring/decimal
|
http://godoc.org/github.com/shopspring/decimal
|
||||||
|
|
Loading…
Reference in a new issue