Skip to content

[Bug]: toDecimal() returns .0 for exponent 0 currencies and should return an integer #751

@jasongitmail

Description

@jasongitmail

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

// Currencies object
"JPY": {
    "code": "JPY",
    "base": 10,
    "exponent": 0
  },
const dineroObj = {
    "amount": 300,
    "currency": {
      "code": "JPY",
      "base": 10,
      "exponent": 0
    },
    "scale": 0
}
console.log(toDecimal(dineroObj))
// result is 300.0, expected 300

This same behavior occurs for other exponent 0 currencies.

Expected behavior

I would expect an integer value to be returned for "exponent 0" currencies, such as 300 for the above example.

Steps to reproduce

  1. Create a dinero object for a base 10, exponent 0 currency (e.g. JPY or VND)
  2. Pass it to toDecimal(dineroObj)) and view the result.

Version

2.0.0-alpha
Note: I'm using Dinero's default JS numbers, not BigInt or other.

Environment

Node v20

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions