Posts tagged with: formatter

antonienko/MoneyFormatter 2.0

I’ve given a small push to my MoneyFormatter library.

First, the Moneyphp/money library (previously mathiasverraes/money) is about to launch its 3.0 version, so I’ve updated the dependency on my Formatter. Although the library was still working perfectly, that change implied dropping php 5.3 support, so it demanded to be released as a new major version.

So since I was creating a new major version, I felt like I could break a few more things: it was time for a change in the names of the methods.

toFloat

The main problem I was having when I decided to create this library, is how to know how many decimal places each currency had by default. The Money library worked with the premise of all currencies using 2 decimal places, which is not correct, so I decided to use the iso4217 library from Alcohol to solve that.

The toFloat method will then return a float number with the appropiate number of decimal places for the currency of the Money object

Locales and formatting

The second problem I was trying to address is how to format Money objects into string with the proper locale representation. The methods toString, toSymbol and getSymbolPosition work with the locale representation always in mind.

The toSymbol comes in two flavors: “just the symbol” or “full symbol”. What does that mean? For example, you have the Dollar. When you have this symbol ‘$’, are you talking about the USA currency? Maybe Canadian Dollars? Or could them be Australian? That’s when you need the “full symbol”, for example ‘CA$’.

For more details on usage, please take a look at the README.


Pages:12