Skip to content

Commit 3bac4bd

Browse files
committed
init
0 parents  commit 3bac4bd

File tree

4 files changed

+1020
-0
lines changed

4 files changed

+1020
-0
lines changed

LICENSE

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Spring, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
22+
23+
- Based on https://github.com/oguzbilgic/fpd, which has the following license:
24+
"""
25+
The MIT License (MIT)
26+
27+
Copyright (c) 2013 Oguz Bilgic
28+
29+
Permission is hereby granted, free of charge, to any person obtaining a copy of
30+
this software and associated documentation files (the "Software"), to deal in
31+
the Software without restriction, including without limitation the rights to
32+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
33+
the Software, and to permit persons to whom the Software is furnished to do so,
34+
subject to the following conditions:
35+
36+
The above copyright notice and this permission notice shall be included in all
37+
copies or substantial portions of the Software.
38+
39+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
40+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
41+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
42+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
43+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
44+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45+
"""

README.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# decimal
2+
3+
Arbitrary-precision fixed-point decimal numbers in go.
4+
5+
NOTE: can "only" represent numbers with a maximum of 2^31 digits after the decmial point.
6+
7+
## Usage
8+
9+
```go
10+
package main
11+
12+
import (
13+
"fmt"
14+
"github.com/jellolabs/decimal"
15+
)
16+
17+
func main() {
18+
price, err := decimal.NewFromString("136.02")
19+
if err != nil {
20+
panic(err)
21+
}
22+
23+
quantity := decimal.NewFromFloat(3)
24+
25+
fee, _ := decimal.NewFromString(".035")
26+
taxRate, _ := decimal.NewFromString(".08875")
27+
28+
subtotal := price.Mul(quantity)
29+
30+
preTax := subtotal.Mul(fee.Add(decimal.NewFromFloat(1)))
31+
32+
total := preTax.Mul(taxRate.Add(decimal.NewFromFloat(1)))
33+
34+
fmt.Println("Subtotal:", subtotal)
35+
fmt.Println("Pre-tax:", preTax)
36+
fmt.Println("Taxes:", total.Sub(preTax))
37+
fmt.Println("Total:", total)
38+
fmt.Println("Tax rate:", total.Sub(preTax).Div(preTax))
39+
}
40+
```
41+
42+
## Documentation
43+
44+
http://godoc.org/github.com/jellolabs/decimal
45+
46+
## License
47+
48+
The MIT License (MIT)

0 commit comments

Comments
 (0)