on ‎2007 Oct 18 4:06 PM
Hello,
I am trying to convert a string to double as:
double d= Doubel.parseDouble(String)
but at runtime it is giving NumberFormatException ....
how do we convert String to Double else....
Any help would be highly appreciated.
Request clarification before answering.
Sridhar,
I tried the code although it's changing the value according to my calculations still it doesen't change the value on the screen where I am trying for...
Looking forward to your reply.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am not sure with your logic. You can print String before you set it to the Context.
like this,
Make sure your QuotasElement Cardinality 1.n.
String str2 = null;
try
{
for(int i=0;i<str.length();i++)
{
char c =str.charAt(i);
if(c!=' '&& c><65)
final_str=final_str+c;
}
double balance =Double.parseDouble(final_str);
balance = balance + addition;
str2 = Double.toString(balance);
wdComponentAPI.getMessageManager().reportSuccess("str2 : "+str2 );
}
catch(Exception e)
{
e.printStackTrace();
}
wdContext.currentQuotasElement().setRest_Posted_Requested(str2);
Regards,
Sridhar
I Dont see any wrong in your code. I would check the value before setting it to the context element. Check in the rest of your program, any where you are setting it to null.
Check one more time, is it setting correct values like this.
String str2 = null;
try
{
for(int i=0;i<str.length();i++)
{
char c =str.charAt(i);
if(c!=' '&& c><65)
final_str=final_str+c;
}
double balance =Double.parseDouble(final_str);
balance = balance + addition;
str2 = Double.toString(balance);
wdComponentAPI.getMessageManager().reportSuccess("str2 : "+str2 );
}
catch(Exception e)
{
e.printStackTrace();
}
wdContext.currentQuotasElement().setRest_Posted_Requested(str2);
wdComponentAPI.getMessageManager().reportSuccess("str2 : "+str2 );
Are you getting any exception, or is it setting null to your context element?
Regards,
Sridhar
Subhash,
I am not clear with your business logic. You want to convert String to Double, and you are converting that double value to String.
I have a Node - TestValueNode
- attribute1
- attribute2
String str = "123";
String str2 = null;
double d = 0.0;
try{
double d= Double.parseDouble(str); // this contains the double value
str2 = Double.toString(d); // this contains the String value same as 'str'
wdContext.currentTestValueNodeElement().setAttribute1(str2);
}catch(NumberFormatException nfe){
}
Write me back about your exact requirement. I can probably help you.
Regards,
Sridhar
Hi,
Assume you have a context value attribute called value of type String. You will read this String value>Convert it to double>Perform an increment operation-->Convert back to String.
String str = wdContext.currentContextElement().getValue();//eg."123"
double d = Double.parseDouble(str);// converted to 123.0
d = d+1;//124.0
wdContext.currentContextElement.setValue(Double.toString(d));//"124.0"
wdComponentAPI.getMessageManager().reportSuccess(wdContext.currentContextElement().getValue());
Warm Regards,
Murtuza
Warm Regards,
Murtuza
Subhash,
If you are getting correct value in both places print 1 and print 2, check your table cell, whether it is correctly mapped to the context element or not?
If table cell is binded to the context element, it should show the value. there no other mistakes, i couldn't see in your code.
String str = wdContext.currentContextElement().getValue();//eg.
wdComponentAPI.getMessageManager().reportSuccess(wdContext.currentContextElement().getValue()); - "123" - <b>Print 1</b>
double d = Double.parseDouble(str);// converted to 123.0
d = d+1;//124.0
wdContext.currentContextElement.setValue(Double.toString(d));//"124.0"
wdComponentAPI.getMessageManager().reportSuccess(wdContext.currentContextElement().getValue()); - <b>Print 2</b>
Regards,
Sridhar
| User | Count |
|---|---|
| 15 | |
| 9 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.