decimal icon indicating copy to clipboard operation
decimal copied to clipboard

Arbitrary-precision fixed-point decimal numbers in Go

Results 140 decimal issues
Sort by recently updated
recently updated
newest added

This adds a "round to even" implementation for unbiased rounding.

I make a same stupid error many times. the error is like the code below ```go a := decimal.NewFromString("123") b := decimal.NewFromString("345") a.Sub(b) // wanted: a = a.Sub(b) ``` I...

I was playing around with the package and ran into a bug when trying to access a decimal key out of a map. **See example:** https://go.dev/play/p/0ja7R0O2JaK Let's say I make...

code in decimal ``` func (d Decimal) NumDigits() int { // Note(mwoss): It can be optimized, unnecessary cast of big.Int to string if d.IsNegative() { return len(d.value.String()) - 1 }...

I find that if we do var zero = decimal.FromString("0.00") Then print zero/ assign it to string after conversion, Instead of printing 0.00, 0 is printed. Similarly if we do...

Adds a new constructor `NewFromUint64(uint64)`, which utilises `big.Int.SetUint64()` existing in Go at least since 1.7 (min supported by `decimal`): https://pkg.go.dev/math/[email protected]#Int.SetUint64 Improves tests of existing constructors from signed int, covering the...

Can we add more frequently used built-in variables like ```go // Zero constant, to make computations faster. // Zero should never be compared with == or != directly, please use...

![截圖 2024-01-30 晚上10 41 07](https://github.com/shopspring/decimal/assets/65802504/e5d78e52-9971-4642-b8ef-3133caa1b9cd) ![截圖 2024-01-30 晚上10 44 53](https://github.com/shopspring/decimal/assets/65802504/4def11d2-02e4-4d73-9763-7ff0a88aa7c9) decimal.NewFromFloat(-1.454).RoundFloor(1).String() -> output would be "-1.5" decimal.NewFromFloat(-1.454).RoundCeil(1).String() -> output would be "-1.4"

The readme states that this library can handle up to 31 precision after the decimal. This is fine until a division operation is performed.

FIX Add functionality to compare if a decimal value is between two decimals #319