PHP code:
public static function formatPrice($data)
{
$price = ($data / 100);
return "€" . number_format($price, 2, ",", ".");
}
public static function formatPrice($data)
{
$price = ($data / 100);
return "€" . number_format($price, 2, ",", ".");
}
Bart Matsko op 26/05/2015 14:56:55
Ik heb in PHP een functie die centen naar euro's omzet, omdat ik in mijn database centen opsla. Nu zoek ik eigenlijk ook zo iets in Javascript, bestaat dat?
PHP code:
public static function formatPrice($data) { $price = ($data / 100); return "€" . number_format($price, 2, ",", "."); }
<script language="JavaScript"><!--
function cent(amount) {
// returns the amount in the .99 format
amount -= 0;
return (amount == Math.floor(amount)) ? amount + '.00' : ( (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}
document.write(cent(0)+'<br>');
document.write(cent(1)+'<br>');
document.write(cent(1.00)+'<br>');
document.write(cent(.5)+'<br>');
document.write(cent(.99)+'<br>');
document.write(cent('5.50')+'<br>');
//--></script>
Daan Slagter op 26/05/2015 15:12:07
<script language="JavaScript"><!-- function cent(amount) { // returns the amount in the .99 format amount -= 0; return (amount == Math.floor(amount)) ? amount + '.00' : ( (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount); } document.write(cent(0)+'<br>'); document.write(cent(1)+'<br>'); document.write(cent(1.00)+'<br>'); document.write(cent(.5)+'<br>'); document.write(cent(.99)+'<br>'); document.write(cent('5.50')+'<br>'); //--></script>
document.write(cent(2200)+'<br>');
var centen = 3000
var euro = (centen2/100).toFixed(2).toString().replace(".", ",");
alert(euro);
Johan de wit op 26/05/2015 15:07:53
[quote="Bart Matsko op 26/05/2015 14:56:55"]
Ik heb in PHP een functie die centen naar euro's omzet, omdat ik in mijn database centen opsla. Nu zoek ik eigenlijk ook zo iets in Javascript, bestaat dat?
PHP code:
public static function formatPrice($data) { $price = ($data / 100); return "€" . number_format($price, 2, ",", "."); }
Randy Flujowa op 26/05/2015 18:27:43
var centen = 3000 var euro = (centen2/100).toFixed(2).toString().replace(".", ","); alert(euro);
Bart Matsko op 27/05/2015 08:52:54
[quote="Randy Flujowa op 26/05/2015 18:27:43"]
var centen = 3000 var euro = (centen2/100).toFixed(2).toString().replace(".", ","); alert(euro);
var cost = $('<span>')
$cost.money((300.234 + 34.234324),{ commas: true, symbol: "$" });
cost.appendTo("#total");
$('<span>').money((300.234 + 34.234324),{ commas: true, symbol: "$" }).appendTo("#total");<div id="total"><span>$334.47</span></div>
Johan K op 27/05/2015 09:58:34
Je kan natuurlijk ook even kijken naar een jQuery plugin.
Zorg dan natuurlijk wel dat je jQuery en deze plugin in de header laad.
https://plugins.jquery.com/money/