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

Currency Formatter java

NumberFormat numberFormat = NumberFormat.getCurrencyInstance(locale);
//the user may have selected a different currency than the default for their locale
Currency currency = Currency.getInstance("GBP");
numberFormat.setCurrency(currency);
numberFormat.format(amount);
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 :: how to find absolute difference in java 
Java :: java read file 
Java :: matrix multiplication javascrpt 
Java :: difference between two LocalDateTime java 
Java :: threads array java 
Java :: this in java 
Java :: object vs class c# 
Java :: statusbar text color android 
Java :: generating random number 
Java :: java dimension 
Java :: which api is android 12 
Java :: string length in android studio java 
Java :: nested list java 
Java :: getcolor deprecated android 
Java :: map initialization java 
Java :: is a and has a relationship in java 
Java :: check stack empty java 
Java :: java random double between 0 and 1 
Java :: how to scan as a letter in java 
Java :: install java using cmd 
Java :: unable to access jarfile 
Java :: set layout params in dp value 
Java :: java foreach backwards 
Java :: Error: Could not find or load main class javafx.controls,javafx.fxml Caused by: java.lang.ClassNotFoundException: javafx.controls,javafx.fxml 
Java :: java int array to integer arraylist 
Java :: java rename file 
Java :: quarkus skip test 
Java :: Create class from string variable JAVA 
Java :: hashmap get value by key java 
Java :: save bitmap file for share on android 10 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =