GithubHelp home page GithubHelp logo

nikolaydubina / fpdecimal Goto Github PK

View Code? Open in Web Editor NEW
29.0 29.0 2.0 137 KB

๐Ÿ›ซ Fixed-Point Decimals

License: MIT License

Go 100.00%
decoding encoding fixed-point-arithmetic go json money numerics performance serialization

fpdecimal's People

Contributors

nikolaydubina avatar vanodevium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fpdecimal's Issues

Equal()

It would be good to have such a method as well

min and max functions

what is the easiest way to perform min/max functions on fpdecemial numbers?

using math.Min or math.Max requires float64 conversations

Pointer receivers

func (a Decimal) Float64() float64 { return float64(a.v) / 1000 }

What is the reason that you declared methods on values and not on references?

func (a *Decimal) Float64() float64 { return float64(a.v) / 1000 }

asterisk before Decimal

Also, my IDE shows me a warning on each method:
Struct Decimal has methods on both value and pointer receivers. Such usage is not recommended by the Go Documentation.

Configuration of amount numbers after point

Your library is super simple but awesome!

Let me explain my point:
You only have two constant numbers in your code: 3 and 1000.
1000 == 10^3.

If 3 was a separate configurable value, a more flexible use of the library could be achieved.

For instance:

fp3.SetNumbersAfterPoint(6)
fp3.FromFloat(1.123456) // -> 1123456
fp3.FromFloat(1.1234567) // -> 1123456

@nikolaydubina How do you like the idea?

losing precision on lower numbers

is there a way to fix losing precision on lower floats
for example

fpdecimal.FromFloat(0.0705)

results to 0.0704 output

my fraction digits is set to 4

func init() {
	fpdecimal.FractionDigits = 4
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.