Number of output decimal places [duplicate]












-2
















This question already has an answer here:




  • Show a number to 2 decimal places

    21 answers




I made a code for calculating Woocommmerce discount...
Sorry for the stupid question, but I can not find a solution.



"division" outputs the "price_per_bottle" devided by "price_per_ltr".
I can not get it to output only 2 decimal places ("12.30" as in €), because now, by default, there are many.



<button id='add' type='button' onclick='ik(this.value);'  value='3'>
30% Discount <span class="kalkc3" id="kalk1"><?php
$price_per_bottle= $product->get_price();
$price_per_ltr= 0.7;
$division = $price_per_bottle/ $price_per_ltr;
echo $division;
?></span></button>


I have found the answer, but not in the mentioned post... But with trial and error:)..



<?php 
$kokstane3 = $product->get_price();
$popust3 = 0.7;
$rezultat3 = $kokstane3 * $popust3;
echo (round($rezultat3,2));// <= HERE
?>









share|improve this question















marked as duplicate by Nigel Ren php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 16 '18 at 9:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 2





    echo round($division, 2);

    – Stender
    Nov 16 '18 at 9:29













  • note - round() will not work, if you have thousands seperator

    – Stender
    Nov 16 '18 at 9:31











  • in which case - you should go with number_format like the answer explains

    – Stender
    Nov 16 '18 at 9:32











  • I highly recommend not to ever use non-English identifiers when programming.

    – connexo
    Nov 16 '18 at 9:36











  • This question appears to be related to PHP, not Javascript/jQuery. Edited the tags.

    – connexo
    Nov 16 '18 at 9:37


















-2
















This question already has an answer here:




  • Show a number to 2 decimal places

    21 answers




I made a code for calculating Woocommmerce discount...
Sorry for the stupid question, but I can not find a solution.



"division" outputs the "price_per_bottle" devided by "price_per_ltr".
I can not get it to output only 2 decimal places ("12.30" as in €), because now, by default, there are many.



<button id='add' type='button' onclick='ik(this.value);'  value='3'>
30% Discount <span class="kalkc3" id="kalk1"><?php
$price_per_bottle= $product->get_price();
$price_per_ltr= 0.7;
$division = $price_per_bottle/ $price_per_ltr;
echo $division;
?></span></button>


I have found the answer, but not in the mentioned post... But with trial and error:)..



<?php 
$kokstane3 = $product->get_price();
$popust3 = 0.7;
$rezultat3 = $kokstane3 * $popust3;
echo (round($rezultat3,2));// <= HERE
?>









share|improve this question















marked as duplicate by Nigel Ren php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 16 '18 at 9:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 2





    echo round($division, 2);

    – Stender
    Nov 16 '18 at 9:29













  • note - round() will not work, if you have thousands seperator

    – Stender
    Nov 16 '18 at 9:31











  • in which case - you should go with number_format like the answer explains

    – Stender
    Nov 16 '18 at 9:32











  • I highly recommend not to ever use non-English identifiers when programming.

    – connexo
    Nov 16 '18 at 9:36











  • This question appears to be related to PHP, not Javascript/jQuery. Edited the tags.

    – connexo
    Nov 16 '18 at 9:37
















-2












-2








-2









This question already has an answer here:




  • Show a number to 2 decimal places

    21 answers




I made a code for calculating Woocommmerce discount...
Sorry for the stupid question, but I can not find a solution.



"division" outputs the "price_per_bottle" devided by "price_per_ltr".
I can not get it to output only 2 decimal places ("12.30" as in €), because now, by default, there are many.



<button id='add' type='button' onclick='ik(this.value);'  value='3'>
30% Discount <span class="kalkc3" id="kalk1"><?php
$price_per_bottle= $product->get_price();
$price_per_ltr= 0.7;
$division = $price_per_bottle/ $price_per_ltr;
echo $division;
?></span></button>


I have found the answer, but not in the mentioned post... But with trial and error:)..



<?php 
$kokstane3 = $product->get_price();
$popust3 = 0.7;
$rezultat3 = $kokstane3 * $popust3;
echo (round($rezultat3,2));// <= HERE
?>









share|improve this question

















This question already has an answer here:




  • Show a number to 2 decimal places

    21 answers




I made a code for calculating Woocommmerce discount...
Sorry for the stupid question, but I can not find a solution.



"division" outputs the "price_per_bottle" devided by "price_per_ltr".
I can not get it to output only 2 decimal places ("12.30" as in €), because now, by default, there are many.



<button id='add' type='button' onclick='ik(this.value);'  value='3'>
30% Discount <span class="kalkc3" id="kalk1"><?php
$price_per_bottle= $product->get_price();
$price_per_ltr= 0.7;
$division = $price_per_bottle/ $price_per_ltr;
echo $division;
?></span></button>


I have found the answer, but not in the mentioned post... But with trial and error:)..



<?php 
$kokstane3 = $product->get_price();
$popust3 = 0.7;
$rezultat3 = $kokstane3 * $popust3;
echo (round($rezultat3,2));// <= HERE
?>




This question already has an answer here:




  • Show a number to 2 decimal places

    21 answers








php






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 11:42







Andrej Gjurin

















asked Nov 16 '18 at 9:23









Andrej GjurinAndrej Gjurin

72




72




marked as duplicate by Nigel Ren php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 16 '18 at 9:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Nigel Ren php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 16 '18 at 9:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 2





    echo round($division, 2);

    – Stender
    Nov 16 '18 at 9:29













  • note - round() will not work, if you have thousands seperator

    – Stender
    Nov 16 '18 at 9:31











  • in which case - you should go with number_format like the answer explains

    – Stender
    Nov 16 '18 at 9:32











  • I highly recommend not to ever use non-English identifiers when programming.

    – connexo
    Nov 16 '18 at 9:36











  • This question appears to be related to PHP, not Javascript/jQuery. Edited the tags.

    – connexo
    Nov 16 '18 at 9:37
















  • 2





    echo round($division, 2);

    – Stender
    Nov 16 '18 at 9:29













  • note - round() will not work, if you have thousands seperator

    – Stender
    Nov 16 '18 at 9:31











  • in which case - you should go with number_format like the answer explains

    – Stender
    Nov 16 '18 at 9:32











  • I highly recommend not to ever use non-English identifiers when programming.

    – connexo
    Nov 16 '18 at 9:36











  • This question appears to be related to PHP, not Javascript/jQuery. Edited the tags.

    – connexo
    Nov 16 '18 at 9:37










2




2





echo round($division, 2);

– Stender
Nov 16 '18 at 9:29







echo round($division, 2);

– Stender
Nov 16 '18 at 9:29















note - round() will not work, if you have thousands seperator

– Stender
Nov 16 '18 at 9:31





note - round() will not work, if you have thousands seperator

– Stender
Nov 16 '18 at 9:31













in which case - you should go with number_format like the answer explains

– Stender
Nov 16 '18 at 9:32





in which case - you should go with number_format like the answer explains

– Stender
Nov 16 '18 at 9:32













I highly recommend not to ever use non-English identifiers when programming.

– connexo
Nov 16 '18 at 9:36





I highly recommend not to ever use non-English identifiers when programming.

– connexo
Nov 16 '18 at 9:36













This question appears to be related to PHP, not Javascript/jQuery. Edited the tags.

– connexo
Nov 16 '18 at 9:37







This question appears to be related to PHP, not Javascript/jQuery. Edited the tags.

– connexo
Nov 16 '18 at 9:37














1 Answer
1






active

oldest

votes


















2














Try with number_format()



$flaschenpreis = $product->get_price();
$literpreis = 0.7;
$division = $flaschenpreis / $literpreis;

$division = number_format((float)$division , 2, '.', '');





share|improve this answer


























  • I am unable to use this... Output is "non existent"

    – Andrej Gjurin
    Nov 16 '18 at 9:36











  • It works! Please check here(phptester.net)

    – mbharanidharan88
    Nov 16 '18 at 9:40


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Try with number_format()



$flaschenpreis = $product->get_price();
$literpreis = 0.7;
$division = $flaschenpreis / $literpreis;

$division = number_format((float)$division , 2, '.', '');





share|improve this answer


























  • I am unable to use this... Output is "non existent"

    – Andrej Gjurin
    Nov 16 '18 at 9:36











  • It works! Please check here(phptester.net)

    – mbharanidharan88
    Nov 16 '18 at 9:40
















2














Try with number_format()



$flaschenpreis = $product->get_price();
$literpreis = 0.7;
$division = $flaschenpreis / $literpreis;

$division = number_format((float)$division , 2, '.', '');





share|improve this answer


























  • I am unable to use this... Output is "non existent"

    – Andrej Gjurin
    Nov 16 '18 at 9:36











  • It works! Please check here(phptester.net)

    – mbharanidharan88
    Nov 16 '18 at 9:40














2












2








2







Try with number_format()



$flaschenpreis = $product->get_price();
$literpreis = 0.7;
$division = $flaschenpreis / $literpreis;

$division = number_format((float)$division , 2, '.', '');





share|improve this answer















Try with number_format()



$flaschenpreis = $product->get_price();
$literpreis = 0.7;
$division = $flaschenpreis / $literpreis;

$division = number_format((float)$division , 2, '.', '');






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 16 '18 at 9:38

























answered Nov 16 '18 at 9:29









mbharanidharan88mbharanidharan88

4,11342455




4,11342455













  • I am unable to use this... Output is "non existent"

    – Andrej Gjurin
    Nov 16 '18 at 9:36











  • It works! Please check here(phptester.net)

    – mbharanidharan88
    Nov 16 '18 at 9:40



















  • I am unable to use this... Output is "non existent"

    – Andrej Gjurin
    Nov 16 '18 at 9:36











  • It works! Please check here(phptester.net)

    – mbharanidharan88
    Nov 16 '18 at 9:40

















I am unable to use this... Output is "non existent"

– Andrej Gjurin
Nov 16 '18 at 9:36





I am unable to use this... Output is "non existent"

– Andrej Gjurin
Nov 16 '18 at 9:36













It works! Please check here(phptester.net)

– mbharanidharan88
Nov 16 '18 at 9:40





It works! Please check here(phptester.net)

– mbharanidharan88
Nov 16 '18 at 9:40





Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python