cancel
Showing results for 
Search instead for 
Did you mean: 

int to decimal or string to decimal

Former Member
0 Kudos

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?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Answers (2)

Answers (2)

Former Member
0 Kudos

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

Former Member
0 Kudos

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