Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java format money

double money = 100.1;
NumberFormat formatter = NumberFormat.getCurrencyInstance();
String moneyString = formatter.format(money);
System.out.println(moneyString);
Comment

Java currency format

double currencyAmount = 1500.00;
// Create a new Locale
Locale usa = new Locale("en", "US");
// Create a Currency instance for the Locale
Currency dollars = Currency.getInstance(usa);
// Create a formatter given the Locale
NumberFormat dollarFormat = NumberFormat.getCurrencyInstance(usa);

// Format the Number into a Currency String
System.out.println(dollars.getDisplayName() + ": " + dollarFormat.format(currencyAmount));
Comment

java format money


public String formatDecimal(float number) {
  float epsilon = 0.004f; // 4 tenths of a cent
  if (Math.abs(Math.round(number) - number) < epsilon) {
     return String.format("%10.0f", number); // sdb
  } else {
     return String.format("%10.2f", number); // dj_segfault
  }
}

Comment

PREVIOUS NEXT
Code Example
Java :: append button java 
Java :: reverse string in java 
Java :: coding collections clear method java 
Java :: linked list sorting in java 
Java :: hide actionbar android 
Java :: iterator constructor java 
Java :: java float get 2 decimals 
Java :: javafx filechooser specific file 
Java :: android save int 
Java :: how to remove components from a JFRame java 
Java :: string to long java 
Java :: java current time millis 
Java :: unable to find bundled java version. flutter 
Java :: android studio close app 
Java :: round off java 2 decimal places 
Java :: array to array list 
Java :: kotlin enable and disable parents view children 
Java :: java printf double 2 decimal places 
Java :: mockito verify not called 
Java :: java get random char from alphabet 
Java :: what is an error in java 
Java :: android retrofit get @query 
Java :: spring boot sql logging 
Java :: java infinitew recursion 
Java :: array to arraylist java 
Java :: @notblank not working in spring boot 
Java :: binary to integer in java 
Java :: how to add elements to an array in java dynamically 
Java :: android studio go to another activity kotlin 
Java :: reflections java 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =