nikolaydubina / fpdecimal Goto Github PK
View Code? Open in Web Editor NEW๐ซ Fixed-Point Decimals
License: MIT License
๐ซ Fixed-Point Decimals
License: MIT License
Thanks for the library!
Can you please tell me how to round decimal from 4 to 2 decimal places?
For example 1234.4567 -> 1234.46.
It would be good to have such a method as well
what is the easiest way to perform min/max functions on fpdecemial numbers?
using math.Min or math.Max requires float64 conversations
What is the main reason that both methods get an int type?
In my opinion, will better if they both receive int64.
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.
Will be nice to have method which returns -1, 0, 1 for sorting purposes.
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?
What is the main reason that both methods get an int type?
In my opinion, will better if they both receive int64.
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
}
What is the main reason that both methods get an int type?
In my opinion, will better if they both receive int64.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.