on 05-20-2008 1:03 PM
Hi, I have a problem which I cant solve. Ive got string downloaded from database, 10 characters long, I "cut" it and I want to display it in 3 different inputfields which are of type Decimal and this is where I stopped...
My question is, how can I transform
string to decimal
integer to decimal
Numbers are small, not decimal at all: 1900-2008, 00-31, 00-12, but I used it couse it didnt provide 0 in inputfield as other types did, it was empty as I wanted it to be. Any idea how to solve this?
Hi Fedor,
You can only convert the numeric sting to decimal.
i.e. if your String is "12345" then you can convert it to decimal.
If your String is "1-2-3" then you cannot convert it to decimal it will throw NumberFormatException.
Here is the example to convert the string to decimal
String strTemp = "12345";
BigDecimal bd = new BigDecimal(Integer.parseInt(strTemp));
Now you can assign this bd value to decimal input field
For integer to decimal:
int iTemp = 12345;
BigDecimal bd = new BigDecimal(Integer.parseInt(iTemp));
You can use substring function of string to cut the string into number of pieces.
Hope this will help you
Thanks
Sandy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
string to decimal
integer to decimal
Numbers are small, not decimal at all: 1900-2008, 00-31, 00-12, but I used it couse it didnt provide 0 in inputfield as other types did, it was empty as I wanted it to be. Any idea how to solve this?
string to decimal
String a = "1234";
double dbl = new Double(a).doubleValue();
integer to decimal
int x=123;
double dbl = new Double(x).doubleValue();
Regards
Ayyapparaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ,
use the below code for conversion
To convert from String to Integer
String s = "0000";
int i = Integer.parseInt(s);
Integer to String
int j = 5;
String a = j+"";
Thanks,
Sunitha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.