number to 2 decimal placed blade
How to I convert 7.5 to 7.50 in a blade template?
Use casual PHP number_format.
@LeBlaireau what are the numbers? Where are they coming from?
number_format($number, 2, '.', ',');
// 2 = decimal places | '.' = decimal seperator | ',' = thousand seperator
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.
@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
@sitesense, I agree, you should never use floats. Decimals are fine too. It purely depends on the project.
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.