Skip to content

[Bug]: halfEven does not round correctly when rounding to 0 #710

@shasderias

Description

@shasderias

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

halfEven does not round correctly when rounding to 0

const dHighPrecision = dinero({ amount: 0, currency: USD, scale: 7 });
const dUnit = transformScale(dHighPrecision, 2, halfEven);

console.log("transformed", toSnapshot(dUnit));
// transformed {amount: 1, currency: Object, scale: 2}

console.log("0/1000", halfEven(0, 1000, calculator));
// 0/1000 1
console.log("0/100", halfEven(0, 100, calculator));
// 0/100 1
console.log("0/10", halfEven(0, 10, calculator));
// 0/10 1
console.log("1/10", halfEven(1, 10, calculator));
// 1/10 1
console.log("5/10", halfEven(5, 10, calculator));
// 5/10 0 (this is correct)
console.log("51/100", halfEven(51, 100, calculator));
// 51/100 1 (this is correct)

Expected behavior

Expected to see the following printed to console.

transformed {amount: 0, currency: Object, scale: 2}
0/1000 0
0/100 0
0/10 0
1/10 0
5/10 0
51/100 1

Steps to reproduce

See

https://codesandbox.io/s/nervous-raman-q7xiyt?file=/main.js
https://q7xiyt.sse.codesandbox.io/

Version

2.0.0-alpha13

Environment

Windows, Chrome - Version 108.0.5359.125 (Official Build) (64-bit)

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