LaravelShoppingcart
LaravelShoppingcart copied to clipboard
Incorrect data type for Cart::total() when total price above 999
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' => ''
same issue stuck on that
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
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 .
These functions do not work when it comes to sending the transaction pennies to Stripe
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.
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 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