Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
575 views
in Technique[技术] by (71.8m points)

wordpress - WooCommerce / PDF Invoice / Round Tax Rate to one decimal

I would like to ask for help, as I am not a dev and dont understand PHP. I have the "PDF Invoice" plugin for WooCommerce on my Wordpress site. And it has a modification to display the tax rate instead of the tax value on the invoice.

'<tr>' .
                        '<td valign="top" width="7%" align="left">' . $item['qty'] . ' x</td>' .
                        '<td valign="top" width="13%">' .  $_product->get_sku() . '</td>' .
                        '<td valign="top" width="48%">' .  stripslashes( $item_name ) . '</td>' .
                        '<td valign="top" width="12%" align="right">'  .  wc_price( $item['line_subtotal'] / $item['qty'], array( 'currency' => $order_currency ) ) . '</td>' .                          
                        '<td valign="top" width="10%" align="right">'  .  100 * ( $item['line_subtotal_tax']/$item['line_subtotal'] ) . '%' . '</td>' .  
                        '<td valign="top" width="10%" align="right">' .  wc_price( ( $item['line_subtotal'] + $item['line_subtotal_tax'] ) / $item['qty'], array( 'currency' => $order_currency ) ). '</td>' .
                        '</tr>';

The following line is supposed to do the tax rate calculation:

     '<td valign="top" width="10%" align="right">'  .  100 * ( $item['line_subtotal_tax']/$item['line_subtotal'] ) . '%' . '</td>' .  

However, the result shows the tax rate with a lot of decimals, like this 7.67178118746%

So the question is, how can I modify the line above to display only one decimal rounded upwards. So the result I need there is 7.7%

Thanks in advance and best Regards, Alex

question from:https://stackoverflow.com/questions/65858561/woocommerce-pdf-invoice-round-tax-rate-to-one-decimal

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I did modify the line above to display only one decimal rounded upwards to get the result like is 7.7%

     '<td valign="top" width="10%" align="right">'  .  round( 100 * ( $item['line_subtotal_tax']/$item['line_subtotal'] ) , 1 ) . '%' . '</td>' 

Thanks :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...