@@ -120,11 +120,12 @@ public function lessThan(Money $other)
120120 * Returns the amount expressed in the smallest units of $currency (eg cents).
121121 * Units are treated as integers, which might cause issues when operating with
122122 * large numbers on 32 bit platforms
123+ * @deprecated Use getAmount() instead
123124 * @return int
124125 */
125126 public function getUnits ()
126127 {
127- return ( int )( $ this ->amount * $ this -> currency -> getMultiplier ()) ;
128+ return $ this ->amount ;
128129 }
129130
130131 /**
@@ -145,7 +146,7 @@ public function getCurrency()
145146
146147 /**
147148 * @param \Money\Money $addend
148- *@return \Money\Money
149+ *@return \Money\Money
149150 */
150151 public function add (Money $ addend )
151152 {
@@ -275,7 +276,22 @@ public static function stringToUnits( $string )
275276
276277 return (int ) $ units ;
277278 }
278-
279+
280+ public function format ()
281+ {
282+ return '$ ' . number_format ($ this ->getAmount () / 100 , 2 );
283+ }
284+
285+ /**
286+ * Convert into formatted amount (hardcoded to USD for the time being).
287+ *
288+ * @return string
289+ */
290+ public function __toString ()
291+ {
292+ return number_format ($ this ->getAmount () / 100 , 2 );
293+ }
294+
279295 /**
280296 * Extracts a formatted money string.
281297 * @example echo Money::USD(500)->formattedString();
@@ -311,6 +327,19 @@ public function formattedString()
311327
312328 return $ prefix . $ value . $ suffix ;
313329 }
314-
315-
330+
331+ public function format ()
332+ {
333+ return '$ ' . number_format ($ this ->getAmount () / 100 , 2 );
334+ }
335+
336+ /**
337+ * Convert into formatted amount (hardcoded to USD for the time being).
338+ *
339+ * @return string
340+ */
341+ public function __toString ()
342+ {
343+ return number_format ($ this ->getAmount () / 100 , 2 );
344+ }
316345}
0 commit comments