mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-25 13:50:49 +01:00
Create helpers.go
helpers.go defines several helper functions for the create of new decimal's from int's that make code using decimal a bit easier to read. Further more it implements a.Max() and a.Min() functions in the same fashion as other arithmetic functions like Add & Sub. (the decimal package already implements Max(d, d2....) and Min(), but these two helper functions are complementary to them. Finally a.Float() is a convenience function for a.Float64() that ignore the precise bool, allowing inline use of the float conversion function
This commit is contained in:
parent
cd690d0c9e
commit
70eaa6c75d
1 changed files with 38 additions and 0 deletions
38
helpers.go
Normal file
38
helpers.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
package decimal
|
||||
|
||||
// Float returns the decimal value as a float64
|
||||
// float is a helper function for float64() and doesnot return bool exact
|
||||
func (d Decimal) Float() float64 {
|
||||
f, _ := d.Float64()
|
||||
return f
|
||||
}
|
||||
|
||||
// NotEqual returns true when d is not equal to d2
|
||||
func (d Decimal) NotEqual(d2 Decimal) bool {
|
||||
return !d.Equal(d2)
|
||||
}
|
||||
|
||||
// Max returns the maximum value between d and d2
|
||||
func (d Decimal) Max(d2 Decimal) Decimal {
|
||||
return Max(d, d2)
|
||||
}
|
||||
|
||||
// Min returns the minimum value between d and d2
|
||||
func (d Decimal) Min(d2 Decimal) Decimal {
|
||||
return Min(d, d2)
|
||||
}
|
||||
|
||||
//NewFromInt returns a decimal with the value of int v
|
||||
func NewFromInt(v int) Decimal {
|
||||
return New(int64(v), 0)
|
||||
}
|
||||
|
||||
//NewFromInt32 returns a decimal with the value of int v
|
||||
func NewFromInt32(v int) Decimal {
|
||||
return New(int64(v), 0)
|
||||
}
|
||||
|
||||
//NewFromInt64 returns a decimal with the value of int v
|
||||
func NewFromInt64(v int64) Decimal {
|
||||
return New(v, 0)
|
||||
}
|
Loading…
Reference in a new issue