Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ArchStanton's avatar

number to 2 decimal placed blade

How to I convert 7.5 to 7.50 in a blade template?

0 likes
9 replies
sitesense's avatar
Level 19
number_format($number, 2, '.', ',');

// 2 = decimal places |  '.' = decimal seperator | ',' = thousand seperator
7 likes
mstnorris's avatar

Without knowing what these numbers are, it is hard to give you the best advice.

If it is currency then you should store them as integers in their lowest units (cents, pence etc).

Other formats will depend on what precision you want.

sitesense's avatar

@mstnorris that's debatable :)

Personally I'm a fan of decimals (not floats). I've dredged through many a debate on the subject and still side with decimals.

If somebody can show me a real world example where decimals fail, I'll eat my hat :P

mstnorris's avatar

@sitesense, I agree, you should never use floats. Decimals are fine too. It purely depends on the project.

finchy70's avatar

How would I get this to happen in a model bind form? Trying to populate the field with a float to two decimals.

Please or to participate in this conversation.