scottlaurent / accounting

Useful Laravel Model functions to help develop debit/credit accounting journals.
MIT License
189 stars 72 forks source link

creditDollars function Round of issue #24

Open venkatsamuthiram opened 4 years ago

venkatsamuthiram commented 4 years ago

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 commented 2 years ago

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 commented 2 years ago

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