Skip to content

Commit 400829b

Browse files
authored
chore: rename AvoidScientificNotation to UseScientificNotation (#416)
1 parent 6540310 commit 400829b

2 files changed

Lines changed: 17 additions & 17 deletions

File tree

decimal.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ var MarshalJSONWithoutQuotes = false
7171
// Setting this value to false can be useful for APIs where exact decimal string representation matters.
7272
var TrimTrailingZeros = true
7373

74-
// AvoidScientificNotation specifies whether scientific notation should be used when decimal is turned
74+
// UseScientificNotation specifies whether scientific notation should be used when a decimal is turned
7575
// into a string that has a "negative" precision.
7676
//
7777
// For example, 1200 rounded to the nearest 100 cannot accurately be shown as "1200" because the last two
78-
// digits are unknown. With this set to false, that number would be expressed as "1.2E3" instead.
79-
var AvoidScientificNotation = true
78+
// digits are unknown. With this set to true, that number would be expressed as "1.2E3" instead.
79+
var UseScientificNotation = false
8080

8181
// ExpMaxIterations specifies the maximum number of iterations needed to calculate
8282
// precise natural exponent value using ExpHullAbrham method.
@@ -1473,7 +1473,7 @@ func (d Decimal) InexactFloat64() float64 {
14731473
//
14741474
// -12.345
14751475
func (d Decimal) String() string {
1476-
return d.string(TrimTrailingZeros, AvoidScientificNotation)
1476+
return d.string(TrimTrailingZeros, UseScientificNotation)
14771477
}
14781478

14791479
// StringFixed returns a rounded fixed-point string with places digits after
@@ -1489,10 +1489,10 @@ func (d Decimal) String() string {
14891489
// NewFromFloat(5.45).StringFixed(3) // output: "5.450"
14901490
// NewFromFloat(545).StringFixed(-1) // output: "540"
14911491
//
1492-
// Regardless of the `AvoidScientificNotation` option, the returned string will never be in scientific notation.
1492+
// Regardless of the UseScientificNotation option, the returned string will never be in scientific notation.
14931493
func (d Decimal) StringFixed(places int32) string {
14941494
rounded := d.Round(places)
1495-
return rounded.string(false, true)
1495+
return rounded.string(false, false)
14961496
}
14971497

14981498
// StringFixedBank returns a banker rounded fixed-point string with places digits
@@ -1508,19 +1508,19 @@ func (d Decimal) StringFixed(places int32) string {
15081508
// NewFromFloat(5.45).StringFixedBank(3) // output: "5.450"
15091509
// NewFromFloat(545).StringFixedBank(-1) // output: "540"
15101510
//
1511-
// Regardless of the `AvoidScientificNotation` option, the returned string will never be in scientific notation.
1511+
// Regardless of the UseScientificNotation option, the returned string will never be in scientific notation.
15121512
func (d Decimal) StringFixedBank(places int32) string {
15131513
rounded := d.RoundBank(places)
1514-
return rounded.string(false, true)
1514+
return rounded.string(false, false)
15151515
}
15161516

15171517
// StringFixedCash returns a Swedish/Cash rounded fixed-point string. For
15181518
// more details see the documentation at function RoundCash.
15191519
//
1520-
// Regardless of the `AvoidScientificNotation` option, the returned string will never be in scientific notation.
1520+
// Regardless of the UseScientificNotation option, the returned string will never be in scientific notation.
15211521
func (d Decimal) StringFixedCash(interval uint8) string {
15221522
rounded := d.RoundCash(interval)
1523-
return rounded.string(false, true)
1523+
return rounded.string(false, false)
15241524
}
15251525

15261526
// Round rounds the decimal to places decimal places.
@@ -1529,7 +1529,7 @@ func (d Decimal) StringFixedCash(interval uint8) string {
15291529
// Example:
15301530
//
15311531
// NewFromFloat(5.45).Round(1).String() // output: "5.5"
1532-
// NewFromFloat(545).Round(-1).String() // output: "550" (with AvoidScientificNotation, "5.5E2" otherwise)
1532+
// NewFromFloat(545).Round(-1).String() // output: "550" (with UseScientificNotation false, "5.5E2" if true)
15331533
func (d Decimal) Round(places int32) Decimal {
15341534
if d.exp == -places {
15351535
return d
@@ -1919,15 +1919,15 @@ func (d Decimal) StringScaled(exp int32) string {
19191919
return d.rescale(exp).String()
19201920
}
19211921

1922-
func (d Decimal) string(trimTrailingZeros, avoidScientificNotation bool) string {
1922+
func (d Decimal) string(trimTrailingZeros, useScientificNotation bool) string {
19231923
if d.exp == 0 {
19241924
return d.rescale(0).getValue().String()
19251925
}
19261926
if d.exp >= 0 {
1927-
if avoidScientificNotation {
1928-
return d.rescale(0).value.String()
1929-
} else {
1927+
if useScientificNotation {
19301928
return d.ScientificNotationString()
1929+
} else {
1930+
return d.rescale(0).value.String()
19311931
}
19321932
}
19331933

decimal_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3868,9 +3868,9 @@ func TestDecimal_StringWithScientificNotationWhenNeeded(t *testing.T) {
38683868
}
38693869

38703870
defer func() {
3871-
AvoidScientificNotation = true
3871+
UseScientificNotation = false
38723872
}()
3873-
AvoidScientificNotation = false
3873+
UseScientificNotation = true
38743874

38753875
tests := []testData{
38763876
{"1.0E3", "1.0E3"}, // 1000 to the nearest hundred

0 commit comments

Comments
 (0)