Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

creditDollars function Round of issue #24

Open
venkatsamuthiram opened this issue Jul 12, 2020 · 2 comments
Open

creditDollars function Round of issue #24

venkatsamuthiram opened this issue Jul 12, 2020 · 2 comments

Comments

@venkatsamuthiram
Copy link

venkatsamuthiram commented Jul 12, 2020

Dear Developer,

I am using your package in my project, I am facing a value round of issue, Please ASAP fix this issue.

Problem Area:

Model : Journal.php
Line No : 206
$value = (int)($value * 100);

public function creditDollars($value, string $memo = null, Carbon $post_date = null): JournalTransaction { $value = (int)($value * 100); return $this->credit($value, $memo, $post_date); }

$value = 32.66
after multiple of 100
$value = 3266.0
$value = (int)($value * 100);
then Execute this line, I got the output= 3265

Suggestion for solve this isssue:

  1. First float value convert to string type -strval(), then convert integer int(), intval()
    $value = (int) strval($value * 100);
  2. Using round() function, then convert to integer
    $value = (int) round($value * 100, 0);

Thank you

@essell
Copy link

essell commented Mar 12, 2022

A easy solution here is to just NOT cast to an int. The money class accepts an integer-ISH value. I spent 3 hours trying to figure this out last night. Precision math is a B

@essell
Copy link

essell commented Mar 12, 2022

It is a bug, for sure, and makes itself evident if you are creating a double entry transaction group.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants