How to output money number by text in java?
How to output money number by text in java?
Example: input: 1234 $
output: one thousand two hundred thirty four dollar.
try this...
import java.text.DecimalFormat;
public class EnglishNumberToWords {
private static final String[] tensNames = {
" ten",
" twenty",
" thirty",
" forty",
" fifty",
" sixty",
" seventy",
" eighty",
" ninety"
private static final String[] numNames = {
" one",
" two",
" three",
" four",
" five",
" six",
" seven",
" eight",
" nine",
" ten",
" eleven",
" twelve",
" thirteen",
" fourteen",
" fifteen",
" sixteen",
" seventeen",
" eighteen",
" nineteen"
private static String convertLessThanOneThousand(int number) {
String soFar;
if (number % 100 < 20){
soFar = numNames[number % 100];
number /= 100;
else {
soFar = numNames[number % 10];
number /= 10;
soFar = tensNames[number % 10] + soFar;
number /= 10;
if (number == 0) return soFar;
return numNames[number] + " hundred" + soFar;
public static String convert(long number) {
// 0 to 999 999 999 999
if (number == 0) { return "zero"; }
String snumber = Long.toString(number);
// pad with "0"
String mask = "000000000000";
DecimalFormat df = new DecimalFormat(mask);
snumber = df.format(number);
// XXXnnnnnnnnn
int billions = Integer.parseInt(snumber.substring(0,3));
// nnnXXXnnnnnn
int millions = Integer.parseInt(snumber.substring(3,6));
// nnnnnnXXXnnn
int hundredThousands = Integer.parseInt(snumber.substring(6,9));
// nnnnnnnnnXXX
int thousands = Integer.parseInt(snumber.substring(9,12));
String tradBillions;
switch (billions) {
case 0:
tradBillions = "";
break;
case 1 :
tradBillions = convertLessThanOneThousand(billions)
+ " billion ";
break;
default :
tradBillions = convertLessThanOneThousand(billions)
+ " billion ";
String result = tradBillions;
String tradMillions;
switch (millions) {
case 0:
tradMillions = "";
break;
case 1 :
tradMillions = convertLessThanOneThousand(millions)
+ " million ";
break;
default :
tradMillions = convertLessThanOneThousand(millions)
+ " million ";
result = result + tradMillions;
String tradHundredThousands;
switch (hundredThousands) {
case 0:
tradHundredThousands = "";
break;
case 1 :
tradHundredThousands = "one thousand ";
break;
default :
tradHundredThousands = convertLessThanOneThousand(hundredThousands)
+ " thousand ";
result = result + tradHundredThousands;
String tradThousand;
tradThousand = convertLessThanOneThousand(thousands);
result = result + tradThousand;
// remove extra spaces!
return result.replaceAll("^\\s+", "").replaceAll("\\b\\s{2,}\\b", " ");
* testing
* @param args
public static void main(String[] args) {
System.out.println("*** " + EnglishNumberToWords.convert(0));
System.out.println("*** " + EnglishNumberToWords.convert(1));
System.out.println("*** " + EnglishNumberToWords.convert(16));
System.out.println("*** " + EnglishNumberToWords.convert(100));
System.out.println("*** " + EnglishNumberToWords.convert(118));
System.out.println("*** " + EnglishNumberToWords.convert(200));
System.out.println("*** " + EnglishNumberToWords.convert(219));
System.out.println("*** " + EnglishNumberToWords.convert(800));
System.out.println("*** " + EnglishNumberToWords.convert(801));
System.out.println("*** " + EnglishNumberToWords.convert(1316));
System.out.println("*** " + EnglishNumberToWords.convert(1000000));
System.out.println("*** " + EnglishNumberToWords.convert(2000000));
System.out.println("*** " + EnglishNumberToWords.convert(3000200));
System.out.println("*** " + EnglishNumberToWords.convert(700000));
System.out.println("*** " + EnglishNumberToWords.convert(9000000));
System.out.println("*** " + EnglishNumberToWords.convert(9001000));
System.out.println("*** " + EnglishNumberToWords.convert(123456789));
System.out.println("*** " + EnglishNumberToWords.convert(2147483647));
System.out.println("*** " + EnglishNumberToWords.convert(3000000010L));
*** zero
*** one
*** sixteen
*** one hundred
*** one hundred eighteen
*** two hundred
*** two hundred nineteen
*** eight hundred
*** eight hundred one
*** one thousand three hundred sixteen
*** one million
*** two millions
*** three millions two hundred
*** seven hundred thousand
*** nine millions
*** nine millions one thousand
*** one hundred twenty three millions four hundred
** fifty six thousand seven hundred eighty nine
*** two billion one hundred forty seven millions
** four hundred eighty three thousand six hundred forty seven
*** three billion ten
}
Similar Messages
-
How to count the number of text boxes that are data entered
How to count the number of text boxes that are data entered in visual basic form.
Here is an Iterator that expands on my previous response:
''' <summary>
''' Iterator for form controls
''' </summary>
''' <param name="onlyControlsOfType">specify type if a certain type of controls needed</param>
''' <param name="onlyTopLevel">if true don't search containers within the form</param>
''' <returns></returns>
''' <remarks></remarks>
Private Iterator Function AllControls(Optional onlyControlsOfType As Type = Nothing, _
Optional onlyTopLevel As Boolean = False) As IEnumerable(Of Control)
Dim ctrl As Control = Me.GetNextControl(Me, True)
Do Until ctrl Is Nothing
If onlyControlsOfType Is Nothing OrElse ctrl.GetType = onlyControlsOfType Then
If TypeOf ctrl.Parent Is Form OrElse Not onlyTopLevel Then
Yield ctrl
End If
End If
ctrl = Me.GetNextControl(ctrl, True)
Loop
End Function
Some sample uses:
For Each
For Each c As Control In AllControls()
Debug.WriteLine(c.Name)
Next
List of all controls, including controls in containers i.e. Groupbox
Dim l As List(Of Control) = AllControls().ToList
List of all Textbox controls, including Textboxes in containers i.e. Groupbox
l = AllControls(GetType(TextBox)).ToList
List of all Textbox controls, don't include Textboxes in containers i.e. Groupbox
l = AllControls(GetType(TextBox), True).ToList
'Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it.' JohnWein
Multics
My Serial Port Answer -
How to output serial number in wwi template from the production order
Dear Experts ,
Has Sap defined report symbol to output serial number in sap glmDear S P
there are "lots" of threads discussing this.
GLM - Serial Number Hide
EHS GLM how to define serial numbers out of a list
Bar Code in SAP GLM
New changes for GLM in EHP7.0 and ERP 6.0
GLM - Serial Number Hide
Sap GLM Serial NUmber printing
Please check them
C.B. -
How to output serial number from production order in GLM ?
how to pull serial number from production order in wwi template for GLM ?
Hi,
Please have a look to this thread:
BAPI/RFC to get serial numbers for a production order
Hope it helps,
Kr,
m. -
How to output strings to an text file and excel file
Hi guys,
I am writing a simple application taht process some string inputs from user using a simple GUI. The GUI consists of a series of
textfields which the user can enter names, age, addresses....etc
Once they complete filling up that GUI form, they click SUBMIT. All the values will then be read. These strings are then required to be output to 2 files
1. To a text file which I can open it and read it anytime I wish.
2. To an excel file which follows a specific format. That is, all names will be written to column B, all ages will be written to column C...etc
The programme is expected to keep running allow the user to enter details of multiple persons(some 300 sets of data of different persons) until he clicks on End program.
Please advise how I can output the strings to
1. Text file
2. Excel file.
Many many thanks. I need this for one of my project which is due so so soon...... :((
Regards
David1. Text file
See link to "Documentation - Tutorials" on the left
side of this page.
2. Excel file
Dont try to write the real excel format (if you want
to do it soon).
- write data to a plain text file.
- Use tab stops for separation of values.
- Name file as excel file. (*.xls)
If you double click this file, excel will import data
and insert it to a table in the right order by
itself.
Excel can save this as real .xls now.
Anyone here with a better idea? (Try to learn by
myself)good thing to know for the excel tip :)
thx -
How to find largest number from text file
I am using the "Read from text file" block to read the data from my .txt file into labview. It is now in string format. I have many numbers in the file.
For example:
0.45
0.35
0.12
1.354
1.56
2.89
5.89
0.56
That is what a text file might look like. I want to find which of these numbers is largest, and do calculations with that number. I am having trouble with strings/number formats/arrays, etc. Thanks
Solved!
Go to Solution.The spreadsheet functions and VIs typically work on strings representing numbers separated by delimiters. This is a typical way to save a "spreadsheet" (of numbers) to a text file, for example .csv files. These are quite versatile and powerful functions. Spend a bit of time becoming familiar with them because you may find yourself using them a lot.
Lynn -
How to extract the number from image using java
Hello every one
i want to develope a project which can extract the number from image
that i can use as inter or String or char.
Is there any API in java which provide this type of facility.
right now i m using java 5
thanks in Advance
JigneshIn my project i have a image in that i have a
co-ordinate (x,y) I am still puzzled as to what you seek. It sounds to me like you have a point (x, y) represented by p. in java it's just p.getX() p.getY()
i want to convert that cordinate to numeric form,
i mena i want to use that cordinate in somewhere else
in project.point.getX() point.getY()
So need to convert it into numeric form u can called
it OCR also.OCR is optical character recognition. If I want out and took a picture of the US Declaration of Independence and then wanted the words on the parchement in the picture in text form, then I would run the picture through a software program and it would try to optically recognise what lettering and number were present in the picture. In the end, I would have a text of what is written on the US Declaration of Independence.
Is that what you want? -
How to display/input/write Chinese Text in java
Dear All,
I am trying to make a very simple java program, where I am trying to display Chinese characters. I am trying to save them into a file (for now, later into db2). However, I seem to make no progress at all.
I am completely lost with this one. I have googled and gone through a lot of sites like :
http://www.mandarintools.com/javaconverter.html
http://www.chinesecomputing.com/programming/java.html
http://forum.java.sun.com/thread.jspa?threadID=442220&messageID=1995079
http://www.linuxforum.net/chinese/develop/java.html
I have downloaded the cyberbit.ttf into /jre/lib/fonts and updated the fonts.properties also.
I have tried to compile with two different encoding options big5 and gb2132 as well.
I have also tried to pick up a few unicodes from a site and tried .. for ex.
String s = "\U+0061";but this results in Illegale Escape Char. exception.
All I am trying to do is use a String reference, feed it with Chinese text, which again I copied from a site, and then display it on the console. Or even write it to a file.
I am lost in the maze of Unicode, UTF -8 etc.
I would be really glad if someone could lead me out of this.
Thanks in advance.
Rgds,Hi,
So I tried to actually start working on the web app where this change is intended.
I copied a chinese String from a website (pasted it in Word, and it pasted fine).
Pasted it in the text box and saved this field. The value appears gibberish in db2 ( I am sure the tables arent specified for UTF-8).
My app doesnt use any contentType or characterEncoding either.
Then when I retrieve this value, it comes as exact same gibberish as in DB.
But, behold, when I change the encoding (view -> encoding -> chinese (GB2312)) It displays the exact String that was inserted :-)
Then I add these lines in my Jsp.
<%@ page contentType="text/html; charset=GB2312" %>
request.setCharacterEncoding("GB2312"); .
so that I can make that chinese GB2312 as the default option. It does that. (The default was Western European (ISO).
However now, it displays question marks (????) in that field.
What options can I have ?
TIA -
How to Output Rich Text Format.
Hi everyone, i use a rich text editor called tiny mce in my web application. After i click the submit button the value inside the text area would be saved in my database including the HTML tags e.g. <i>Sample Report edited via Tiny MCE Rich Text Editor<i>. I need to output the text in a webuijsf static text component but the moment i see the output the tags are still there and the text is not in italics format. Does anyone know how to output it in static text with the design in it?
It is not updated for more than 1 years and it is dropped by Sun and users were recommended to migrate to ICEfaces.
[http://woodstock.dev.java.net]
The Woodstock release 4.2 is the last official version of Woodstock that Sun will release. Sun will continue to support its customers that have built on top of Woodstock 4.2. The Project Woodstock code is still available, and community members can still create new features or enhancements. For future development or migration of existing Woodstock projects, Sun is officially endorsing ICEfaces as the replacement technology for Woodstock. Also see [http://www.nabble.com/Woodstock-Migration-Path-to-ICEfaces-td21057513.html], although I would recommend RichFaces above that. It is only that it doesn't have a drag'n'drop palette for Netbeans, so it is not reachable for blind visual developers. -
How to convert number to string in java
hi how can i convert number to string in java
something like
public void Discription(Number ownerName){
String.valueOf(ownerName);Edited by: adf009 on 2013/04/08 7:14 PMYet another way of doing it is: ownerName.toString().
If you are working in and IDE such as Netbeans or Eclipse, type a period after the object name. Wait a second or so. Eclipse/Netbeans Intellisense will show you a list of functions that object provides that you can choose from. toString() is one of them. -
How to find the number of occurance of a string in text field of Infopath form?
Hi All,
In Infopath text field, How to find the number of occurrence of a particular string in that field?
Thanks in advance!You can check to see if it contains a string once by using the contains function, but there isn't a very clean way to do what you want. If you wanted to guess at the maximum number of occurrences, then you could:
Box A has your initial. Set Box B to do a concat of string-before and string-after of Box A where it copies Box A minus the string we're looking for. Then we have Box C that does the same thing to Box B. Repeat as many times as you see necessary.
Example:
String: "1"
Box A - "123451234512345"
Box B - "23451234512345"
Box C - "2345234512345"
Box D - "234523452345"
etc.
We then have a field that has nested ifs looking backwards from Z -> A looking for a non-blank. Based on that, we return the number of occurrences. Again, this isn't clean, but it will work if you think there's a predefinable maximum.
Andy Wessendorf SharePoint Developer II | Rackspace [email protected] -
How to get paragraph number of selected text in ID CS4
Hi,
Can anybody help me how to get paragraph number of selected text in Indesign cs4.
Thanks,
GopalAh, I see -- thanks. Turns out that there's no difference in speed between texts.itemByRange(), characters.itemByRange(),and insertionPoints.itemByRange(). In a document with 170 pages of text, and with the cursor in the last paragraph, the second and third lines, below (and your function), give exactly the same result:
t = app.selection[0];
t.parentStory.texts.itemByRange (t.parentStory.insertionPoints[0], t).paragraphs.length;
t.parentStory.characters.itemByRange (t.parentStory.characters[0], t).paragraphs.length;
Peter -
How to output a query results into a text file
How to output a query results into a text file instead of outputing it to the screen..
is there a way for us to write a SQL query which specifies to output the query results to a text file.
Pls let me know how to do it
Thanking u in advance
regards
MuralyMuraly,
If you are using SQL*Plus 8.1.6 or later, you can also spool output to a file in HTML format, eg
SET MARKUP HTML ON SPOOL ON PREFORMAT OFF ENTMAP ON
SPOOL c:\temp\report.html
SELECT DEPARTMENT_NAME, CITY
FROM EMP_DETAILS_VIEW
WHERE SALARY>12000;
SPOOL OFF
SET MARKUP HTML ENTMAP OFF
In iSQL*Plus 9.0.1 (the browser-based interface to SQL*Plus) onwards, you can also send the HTML output to a new web browser window, or an html file -- much easier than the command line method.
Alison -
How to increase the number of characters in Text Edit??
Hi,
How to increase the number of characters we enter in the Text Edit, for example i can't enter not more than 255 characters. If to enter upto 500 char, what to do.
Thanks and regards,
KarthikWe can't restrict the number of characters a UI element can take. Rows and columns properties are to specify the visible no of rows and columns.
If u want a restriction in the number of characters you have to create a simple type and set it to a context attribute and then map it to the text view. -
How to output column of text to array
Hi,
In attached vi,
How can I output all column of text into 1D array? I only able to read the first line.
Thanks.
Attachments:
1.vi 8 KBI downconverted Freelance_LV's example to 8.5 for you.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Attachments:
1_edited.vi 8 KB
Maybe you are looking for
-
Hi, as an Aperture newbie I am looking for a way to resize images in Aperture. Ie, the equivalent to Photoshop CS2's 'Image>Image Size', which allows me to, for example, just increase the pixels per inch of an image. For example I have been doing thi
-
Building array and writing to multiple files
Greetings, I have a VI wherein, I am collecting data from 3 channels (using Global Virtual Channels with scaling). I am collecting 100 samples at a time with sampling frequency of 1000 Hz. I am then taking average and st. dev of 100 data points/chann
-
Check the frequency a report is run
Hello experts, I like to know if there is a way to find out how often a custom abap report is run and who the user is ? Is there anything in sap that i can use ? Any suggestions is appreciated and awarded. Thanks Joyce
-
Hi All, After having installed an updated version of a process I'm trying to migrate a single instance to the new version. Since the instance is in Pending Migration I see the button "Migrate". When I click this the system is busy for a while and end
-
I want to remove some music from my iPhone
I removed a few songs from iTunes (I pressed "Keep files) but the music still syncs to the iPhone. How can I remove it?