LaravelShoppingcart icon indicating copy to clipboard operation
LaravelShoppingcart copied to clipboard

Incorrect data type for Cart::total() when total price above 999

Open aarongtz opened this issue 6 years ago • 7 comments

Data type of the returned value of Cart::total() returns a string when above 999, even if default thousand separator is specified as empty 'thousand_seperator' => ''

aarongtz avatar Apr 11 '18 22:04 aarongtz

same issue stuck on that

varun2948 avatar Jun 30 '19 16:06 varun2948

same issue stuck on that

I'd recommend you always convert the value to the correct one, either using intval() floatval() PHP functions or casting it (int)$value, (float)$value

aarongtz avatar Jun 30 '19 20:06 aarongtz

Thank u so much for the suggestion bt i solved the problem by removing thousand separator from cart.php ☺️

On Mon, Jul 1, 2019, 1:55 AM aarongtz [email protected] wrote:

same issue stuck on that

I'd recommend you always convert the value to the correct one, either using intval() floatval() PHP functions or casting it (int)$value, (float)$value

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Crinsane/LaravelShoppingcart/issues/449?email_source=notifications&email_token=AJA4ZKT4U4DERWFSVSQVQFTP5EHLTA5CNFSM4E2DNQOKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODY4S33Y#issuecomment-507063791, or mute the thread https://github.com/notifications/unsubscribe-auth/AJA4ZKRALDZ3EZLD6JFMOJTP5EHLTANCNFSM4E2DNQOA .

varun2948 avatar Jul 01 '19 01:07 varun2948

These functions do not work when it comes to sending the transaction pennies to Stripe

deyvsonaguiar avatar Jan 24 '20 03:01 deyvsonaguiar

The total() method does make use of number_format which in fact always returns a string. This also holds true for all other methods that allow you to pass the seperators as a parameter and @aarongtz is right that you should cast it to the correct type, but keep in mind that you will then loose the formatting of number_format as it becomes a raw float/int again.

bumbummen99 avatar Jan 24 '20 10:01 bumbummen99

The total() method does make use of number_format which in fact always returns a string. This also holds true for all other methods that allow you to pass the seperators as a parameter and @aarongtz is right that you should cast it to the correct type, but keep in mind that you will then loose the formatting of number_format as it becomes a raw float/int again.

Just wondering, wouldn't it be more appropriate to return the raw total?, as it's better to let us handle the data as we need. :)

aarongtz avatar Jan 28 '20 20:01 aarongtz

@aarongtz well depends on opinion i think. Someone who just does need a string will prefer the built in number format, everyone else has to cast. Except of that it does also limit the amount of decimals.

I think this discussion might be related as there is also round() which does limit the decimals and does return as float. https://github.com/bumbummen99/LaravelShoppingcart/issues/58

bumbummen99 avatar Jan 28 '20 20:01 bumbummen99