Mitch Evans
Mitch Evans

Reputation: 641

Echo out 16.97 without the decimal place

So just like the title says, I have the need to echo out 16.97

16.97 is actually an example of a calculation done with php

I am using Stripe as my payment processor and the charge amount needs to be passed without decimal places. So 16.97 for example needs to display as 1697

Right now this is what I have and it shoots out 17 rather than 1697, I assume it is rounding.

data-amount="<?php echo number_format($grandTotal);?>" 

$grandTotal is a value set up in my php like so:

$grandTotal = $get_row['price']*$value+$get_row['shipping'];

All of these have decimal places but when I get to sending information to stripe, it doesn't need the decimal place.

I have tried multiple solutions from stackoverflow as well google and nothing worked.

So my question is what do I need to do to:

data-amount="<?php echo number_format($grandTotal);?>" 

or more specifically just number_format($grandTotal); to receive a number with no decimal places. I've read that number_format always rounds, so is there another way to do this? I hope this makes sense. If not ask questions in comments!

Upvotes: 1

Views: 270

Answers (1)

aynber
aynber

Reputation: 23034

Either multiply by 100:

$grandTotal = $grandTotal * 100; // (moves decimal 2 places to right)

or remove the periods:

$grandTotal = str_replace('.','',$grandTotal);

Upvotes: 4

Related Questions