Solved

# convert from string to decimal

Posted on 2009-02-22
1,203 Views
folks below i have code , but it is supposed to be a decimal and not a string

how do i successfullly convert this
``````String charge =mbo.getString("LOCATIONSPEC-RATE.NUMVALUE");

if (charge==null) charge ="" ;

mbo.setValue("costs", charge);
``````
0
Question by:rutgermons

LVL 12

Expert Comment

Use
Float.parseFloat(charge);
0

LVL 12

Expert Comment

String charge =mbo.getString("LOCATIONSPEC-RATE.NUMVALUE");
if (charge==null) charge ="" ;
mbo.setValue("costs", Float.parseFloat(charge));

http://vpgupta.blogspot.com/2006/09/difference-between-xxxvalue-parsexxx.html
0

Author Comment

whats the solution then?
0

LVL 12

Expert Comment

mbo.setValue("costs", Float.parseFloat(charge));   ---> ?

Can you explain the question in detail ? What is the expected output with example ?
0

Author Comment

LOCATIONSPEC-RATE.NUMVALUE is actually a decimal value

and the output should be decimal too
0

LVL 86

Accepted Solution

>>LOCATIONSPEC-RATE.NUMVALUE is actually a decimal value

In that case, why not do the following? Obviously, i don't know the type and methods of 'mbo'. If i did, i could help you more precisely

``````mbo.setValue("costs", mbo.getDouble("LOCATIONSPEC-RATE.NUMVALUE"));
``````
0

LVL 92

Expert Comment

sounds like it should be this:

mbo.setValue("costs", mbo.getValue("LOCATIONSPEC-RATE.NUMVALUE"));

Let me know what mbo is and I'll check it for you.

0

LVL 86

Expert Comment

:-)
0

## Featured Post

### Suggested Solutions

tenRun challenge 28 67
nested interface 5 29
scoresAverage challenge 8 58
Fibonacci challenge 11 61
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements: