Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Inserting Comma in a decimal number
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


shriram
Inserting Comma in a decimal number
1 Answer(s)      6 years and 9 months ago
Posted in : Java Beginners


Hi, I want to insert comma in a number that contains decimals also. How can I get 99,999.99 when I have 99999.99. Please tell me. I need it urgently. Thanks a Lot


Advertisement
View Answers

April 23, 2008 at 8:21 PM


Hi friend,

import java.io.*;
import java.util.*;
import java.text.*;

public class CommaInsert {

static public void customFormat(String pattern, double value ){
DecimalFormat myFormatter = new DecimalFormat(pattern);
String str = myFormatter.format(value);
System.out.println(value + " " + pattern + " " + str);
}

static public void localizedFormat(String pattern, double value, Locale local ){
NumberFormat numformate = NumberFormat.getNumberInstance(local);
DecimalFormat decformate = (DecimalFormat)numformate;
decformate.applyPattern(pattern);
String str = decformate.format(value);
System.out.println(pattern + " " + str + " " + local.toString());
}

static public void main(String[] args) {
customFormat("###,###.###", 1000.789);
customFormat("###.##", 1500.789);
customFormat("000000.000", 123.78);
customFormat("$###,###.###", 12345.67);
customFormat("\u00a5###,###.###", 12345.67);

Locale currentLocale = new Locale("en", "US");

DecimalFormatSymbols unusualSymbols = new DecimalFormatSymbols(currentLocale);
unusualSymbols.setDecimalSeparator('|');
unusualSymbols.setGroupingSeparator('^');
String strange = "#,##0.###";

DecimalFormat weirdFormatter = new DecimalFormat(strange, unusualSymbols);

weirdFormatter.setGroupingSize(4);
String bizarre = weirdFormatter.format(12345.678);
System.out.println(bizarre);

Locale[] locales = { new Locale("en", "US"),new Locale("de", "DE"),new Locale("fr", "FR")};

for (int i = 0; i < locales.length; i++) {
localizedFormat("###,###.###", 123456.789, locales[i]);
}
}
}


-----------------------------


Related Tutorials/Questions & Answers:
Inserting Comma in a decimal number - Java Beginners
Inserting Comma in a decimal number  Hi, I want to insert comma in a number that contains decimals also. How can I get 99,999.99 when I have 99999.99. Please tell me. I need it urgently. Thanks a Lot  Hi friend,import
Checking the decimal whether comma used or not
Checking the decimal whether comma used or not  I need to check the given integer whther comma used or not. For example. If the user given 123456... be like 123,456.5 The comma has to be filled from the right side after 3 digits
Advertisements
How to round a number to n decimal places in Java
How to round a number to n decimal places in Java  How to round a number to n decimal places in Java
php format number to 2 decimal places
php format number to 2 decimal places  Hi, How to format a number in PHP to 2 decimal places? Can anyone provide me good code for php format number to 2 decimal places? Thanks
JavaScript for decimal number comparisons - Java Beginners
JavaScript for decimal number comparisons  Hi, I need to compare a BigDecimal in my javascript. I need a have a validation the text field value should not exceed (15,2) (max value is : 9999999999999.99). I am not able
Convert Hexadecimal to Decimal
a hexadecimal number into decimal. Code Description: This program takes a hexadecimal number at console and converts it into a decimal number using parseInt() method... into a decimal number.  parseInt(): This method takes two arguments
Convert Decimal to Octal
; In this section, you will learn to convert decimal number into octal.... Description of code: This program takes a decimal number at console and converts... . The toString() method converts decimal number  into the octal number
Convert Decimal to Integer
; In this section, you will learn to convert  a decimal number... a decimal number to an integer type number. Description Code: This program helps you...:\corejava>java DecimalToInteger Enter the Decimal number: 13
Conversion of Decimal to Binary in Java
Conversion of Decimal to Binary  in Java In this section we will discuss about conversion of Decimal to Binary in Java. You know that number having base 10 is a decimal number, for example 10 is a decimal number which can
Convert Decimal into Binary
;    In this section, you will learn to convert decimal number...; a decimal number into a binary number.  Description of program: This program takes a decimal number from console and it converts it  into binary format
Convert Octal to Decimal
to decimal. The following program helps you converts number octal to decimal. ... it into decimal number using parseInt() method. This method parses.... And you get the decimal number. Integer.parseInt(oct, 8): This method
Convert Binary to Decimal
number  into a decimal number. The java.lang package provides the facility to convert the integer data into the binary to decimal.  Code Description... Convert Binary to Decimal      
Convert Decimal To Fraction
;  In this example, you will learn how to convert decimal number... will also learn how to convert a decimal number into fraction with the help... type variable by using parseInt() method which converts decimal number
Java binary to decimal
to a decimal number. In this Tutorial we want to describe you a code that help you in understanding a how to get a 'Java binary to decimal'. For this we have... Java binary to decimal   
Convert Decimal To Character
. In this example, we are going to convert decimal number to its corresponding character...;java DecimalToASCII Enter the Decimal number: 65 Enter decimal number is:=65 ASCII OF:=A C:\corejava>
remove comma from string php
remove comma from string php  How to remove the last comma from the string in PHP
decimal to hexadecimal
decimal to hexadecimal  using array in java convert decimal to hexadecimal.   Hi, Please see the example Convert Decimal to Hexadecimal. Thanks
PHP Comma vs Period - PHP
PHP Comma vs Period  Explain PHP Comma vs Period. And also how can one show a comma within a comma separated file.   Hi Friend, Please visit the following link: http://www.roseindia.net/tutorial/php/phpbasics/PHP
convert to decimal
convert to decimal  f42a4 convert to decimal by using java
remove comma from string php
remove comma from string php  How to remove the last comma from the string in PHP?   remove last comma from string names = names.replaceAll(",$", ""); //Or a simple substring: if (names.endsWith(",")) { names
BINARY TO DECIMAL - Java Beginners
TO DECIMAL  Hi friend, Program to convert Binary To Decimal : import... (System.in); System.out.print ("Enter a binary number "); String str = sc.next (); int bttm = 1; int decimal = 0; for (int i = str.length
php comma delimited string to array - PHP
php comma delimited string to array  how can we split comma delimited string in to an array
php comma delimited string to array - PHP
php comma delimited string to array  how can we split comma delimited string in to an array
SQL Decimal
SQL Decimal       SQL Decimal is used to specify the values in decimal datatype. The Decimal datatype can be of two types : Decimal (p) refers to floating point and Decimal fixed
Decimal Format Issue Java
Decimal Format Issue Java  Decimal Format Issue Java
swing program for decimal to binary
swing program for decimal to binary  swing program for decimal to binary
JavaScript validation for decimal number
JavaScript validation for decimal number Here we are going to validate the text field value. For this, we have allowed the user to enter decimal number... it. If it contains the decimal sign (.) and it is a number then it will be declared as valid
Convert Decimal to Hexadecimal
a decimal number at console and converts it  into the hexadecimal format using... Convert Decimal to Hexadecimal       In this section, you will learn to convert a decimal data
Round the Decimal values
Round the Decimal values  How to round the decimal value with out using Math.round() Example:round the 2.7 as a 3.0 round the 2.4 as a 2.0
Java arraylist to comma separated string
arrayList is converted into the comma separated string. For this take one by one element from the arrayList. Then add it to the String array. Example of Java Arraylist Comma Separated String import java.util.ArrayList
inserting data into datafields
inserting data into datafields  I was raised with a query.... there is a button, on click on it....... few fields regenerates and the details entered there should be inserted into Database Number of times we click that button
 

 

 

DMCA.com