Inserting Comma in a decimal number

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

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
Write a program in Java to convert Decimal number into Binary number
Write a program in Java to convert Decimal number into Binary number  Hi, I have decimal number and I want to convert it to Binary. How to Write a program in Java to convert Decimal number into Binary number? 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:ADS_TO_REPLACE_1 This program takes a hexadecimal number at console and converts it into a decimal number using...; to convert a hexadecimal into a decimal number.  parseInt(): This method takes two
Convert Decimal to Octal
; In this section, you will learn to convert decimal number into octal..._TO_REPLACE_1 Description of code: This program takes a decimal number at console... to represent a  specified integer. It converts the decimal number into octal
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:ADS_TO_REPLACE_1... the Decimal number: 13 Integer number is:= 13 C:\corejava>
Conversion of Decimal to Binary in Java
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... a decimal number in the command line argument  and divide that number
Convert Decimal into Binary
;    In this section, you will learn to convert decimal number...; a decimal number into a binary number.  Description of program:ADS_TO_REPLACE_1 This program takes a decimal number from console and it converts it 
Convert Octal to Decimal
to decimal. The following program helps you converts number octal to decimal. ... at console converts it into decimal number using parseInt() method. This method... by the second argument as 8. And you get the decimal number. Integer.parseInt(oct, 8
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:ADS... Convert Binary to Decimal      
Convert Decimal To Fraction
;  In this example, you will learn how to convert decimal number... In this program you will also learn how to convert a decimal number into fraction... decimal number into fraction by using doubleValue() method. Here is the code
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... number: 65 Enter decimal number is:=65 ASCII... Convert Decimal To Character     
ModuleNotFoundError: No module named 'comma'
ModuleNotFoundError: No module named 'comma'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'comma' How to remove the ModuleNotFoundError: No module named 'comma'
decimal to hexadecimal
decimal to hexadecimal  using array in java convert decimal to hexadecimal.   Hi, Please see the example Convert Decimal to Hexadecimal. (adsbygoogle = window.adsbygoogle || []).push({}); Thanks
convert to decimal
convert to decimal  f42a4 convert to decimal by using java
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
remove comma from string php
remove comma from string php  How to remove the last comma from the string in PHP
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
java replace dot with comma
java replace dot with comma  Hi, How to replace dot with command in Java program? thanks   Hi, Here is simple example for replacing the dot(.) with comma: package test.app; public class JavaStringExample
java replace dot with comma
java replace dot with comma  Hi, How to replace dot with command in Java program? thanks   Hi, Here is simple example for replacing the dot(.) with comma: package test.app; public class JavaStringExample
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
ModuleNotFoundError: No module named 'oxford_comma'
ModuleNotFoundError: No module named 'oxford_comma'  Hi, My Python... 'oxford_comma' How to remove the ModuleNotFoundError: No module named 'oxford_comma' error? Thanks   Hi, In your python
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
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
swing program for decimal to binary
swing program for decimal to binary  swing program for decimal to binary
Decimal Format Issue Java
Decimal Format Issue Java  Decimal Format Issue Java
Convert Decimal to Hexadecimal
This program takes a decimal number at console and converts it ... Convert Decimal to Hexadecimal       In this section, you will learn to convert a decimal data
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
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
Inserting Data into mysql - SQL
Inserting Data into mysql  My sincere apologize for this post. I... (using php)and inserting the details in a mysql database. Lets take for instance... with the following fields: isbn, title, author, number of pages, reviews. Your usual
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
Formatting and Parsing a Number for a Locale
' as their decimal point, Germany use comma as their decimal point etc. In the given...Formatting and Parsing a Number for a Locale In this section, you will learn how to format and parse a number for a Locale. Formatting converts a date, time
How to convert binary to decimal in Java?
we are going to convert a binary number to it decimal representation... and then converting it to a decimal number. The java.lang package provides... concerts Binary to Decimal in Java. Computer is based on the binary number
ModuleNotFoundError: No module named 'add-trailing-comma'
ModuleNotFoundError: No module named 'add-trailing-comma'  Hi, My... named 'add-trailing-comma' How to remove the ModuleNotFoundError: No module named 'add-trailing-comma' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'delete-last-comma'
ModuleNotFoundError: No module named 'delete-last-comma'  Hi, My... named 'delete-last-comma' How to remove the ModuleNotFoundError: No module named 'delete-last-comma' error? Thanks   Hi, In your
conversion from decimal to hexadecimal and vice versa
conversion from decimal to hexadecimal and vice versa  can i get the code for converting decimal to hexadecimal   Here is a code that converts decimal to hexadecimal. import java.io.*; public class
converting From Hexadecimal to Decimal System - Java Interview Questions
converting From Hexadecimal to Decimal System  Write a program in Java user is required to enter a number system XVI and turn it into the decimal... { public static void main(String args[]) { int decimal=0; Scanner input=new
inserting image into database
inserting image into database  how to insert image into database using struts frame work and spring JDBC
java program (integer/decimal) - Java Beginners
java program (integer/decimal)  Accept a number from the user as command line arguments. The number could be an integer or decimal value. ? Display the absolute value of the input number ? Display the rounded off value
java program to convert decimal in words
java program to convert decimal in words  write a java program to convert a decimal no. in words.Ex: give input as 12 output must be twelve
How to split string in Java using comma?
How to split string in Java using comma?  Hi, Share the example code for splitting the string in Java using comma as separator. Thanks   Hi, You can use the split() function of the String class to split the string
ModuleNotFoundError: No module named 'micropython-decimal'
ModuleNotFoundError: No module named 'micropython-decimal'  Hi, My... named 'micropython-decimal' How to remove the ModuleNotFoundError: No module named 'micropython-decimal' error? Thanks   Hi
ModuleNotFoundError: No module named 'pycopy-decimal'
ModuleNotFoundError: No module named 'pycopy-decimal'  Hi, My... named 'pycopy-decimal' How to remove the ModuleNotFoundError: No module named 'pycopy-decimal' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pycopy-decimal'
ModuleNotFoundError: No module named 'pycopy-decimal'  Hi, My... named 'pycopy-decimal' How to remove the ModuleNotFoundError: No module named 'pycopy-decimal' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'decimal-monkeypatch'
ModuleNotFoundError: No module named 'decimal-monkeypatch'  Hi, My... named 'decimal-monkeypatch' How to remove the ModuleNotFoundError: No module named 'decimal-monkeypatch' error? Thanks   Hi

Ads