Skip to content

Number() gives exponent formatting sometimes #25

Closed
@plarsson

Description

When using the RoundTo method with a precision of 8 and RoundHalfUp rounding mode on a zero amount, the Number method returns "0E-8" instead of "0.00000000". This inconsistency in formatting can cause confusion. Here's a snippet to reproduce the issue:

package main

import (
	"fmt"
	"github.com/bojanz/currency"
)

func main() {
	c, _ := currency.NewAmountFromInt64(0, "SEK")
	c = c.RoundTo(8, currency.RoundHalfUp)
	fmt.Printf("%s\n", c.Number())
}

The apd.Decimal String() defaults to use d.Text('G') which is intended?

// 'G' like 'E' for large exponents, like 'f' otherwise

One fix would be to change Number() to use apd.Decimal.Text('f') method but that will be a breaking change

It would be nice to be able to output Number() without exponents.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions