Skip to content

Commit

Permalink
added notes re AvoidScientificNotation
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnAD committed Dec 9, 2024
1 parent 6453f65 commit ae252ab
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,8 @@ func (d Decimal) String() string {
// NewFromFloat(5.45).StringFixed(2) // output: "5.45"
// NewFromFloat(5.45).StringFixed(3) // output: "5.450"
// NewFromFloat(545).StringFixed(-1) // output: "540"
//
// Regardless of the `AvoidScientificNotation` option, the returned string will never be in scientific notation.
func (d Decimal) StringFixed(places int32) string {
rounded := d.Round(places)
return rounded.string(false, true)
Expand All @@ -1514,13 +1516,17 @@ func (d Decimal) StringFixed(places int32) string {
// NewFromFloat(5.45).StringFixedBank(2) // output: "5.45"
// NewFromFloat(5.45).StringFixedBank(3) // output: "5.450"
// NewFromFloat(545).StringFixedBank(-1) // output: "540"
//
// Regardless of the `AvoidScientificNotation` option, the returned string will never be in scientific notation.
func (d Decimal) StringFixedBank(places int32) string {
rounded := d.RoundBank(places)
return rounded.string(false, true)
}

// StringFixedCash returns a Swedish/Cash rounded fixed-point string. For
// more details see the documentation at function RoundCash.
//
// Regardless of the `AvoidScientificNotation` option, the returned string will never be in scientific notation.
func (d Decimal) StringFixedCash(interval uint8) string {
rounded := d.RoundCash(interval)
return rounded.string(false, true)
Expand All @@ -1532,7 +1538,7 @@ func (d Decimal) StringFixedCash(interval uint8) string {
// Example:
//
// NewFromFloat(5.45).Round(1).String() // output: "5.5"
// NewFromFloat(545).Round(-1).String() // output: "550"
// NewFromFloat(545).Round(-1).String() // output: "550" (with AvoidScientificNotation, "5.5E2" otherwise)
func (d Decimal) Round(places int32) Decimal {
if d.exp == -places {
return d
Expand Down

0 comments on commit ae252ab

Please sign in to comment.