| 1 |
package com.paymentlink.util; |
| 2 |
|
| 3 |
public class CurrencyUtil { |
| 4 |
|
| 5 |
|
| 6 |
* Convert dollars to cents |
| 7 |
*/ |
| 8 |
public static long dollarsToCents(double dollars) { |
| 9 |
return Math.round(dollars * 100); |
| 10 |
} |
| 11 |
|
| 12 |
|
| 13 |
* Convert cents to dollars |
| 14 |
*/ |
| 15 |
public static double centsToDollars(long cents) { |
| 16 |
return cents / 100.0; |
| 17 |
} |
| 18 |
|
| 19 |
|
| 20 |
* Format cents as currency string |
| 21 |
*/ |
| 22 |
public static String formatCents(long cents, String currency) { |
| 23 |
return String.format("%s %.2f", currency, centsToDollars(cents)); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
|