Skip to content

[Bug]: The toFormat method does not allow placing the currency symbol at the end and removes the decimals #774

@fxgal

Description

@fxgal

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Description: I have found an issue with the toFormat method of the dinerojs library. When I try to format a monetary amount with the currency symbol at the end, the method removes the decimals from the amount.

Current behavior: The toFormat method removes the decimals when the currency symbol is placed at the end, displaying "10" instead of "10.51€".

Expected behavior

The toFormat method should allow placing the currency symbol at the end without removing the decimals. In the provided example, it should display "10.51€".

Steps to reproduce

  1. Create an instance of Dinero with an amount that includes decimals.
  2. Use the toFormat method to format the amount with the currency symbol at the end.

Example code:

const Dinero = require('dinero.js');

const amount = Dinero({ amount: 1051, currency: 'EUR' });
const formattedAmount = amount.toFormat('0,0.00$');

console.log(formattedAmount); // Should display "10.51€", but displays "10"

Version

1.9.1

Environment

NodeJs v18.19.0

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