Skip to Content
avatar image
Former Member

How to convert String like "7,00" to "7.00"

Hi Experts,

I have to convert String from "7,00" to "7.00". I tried using replace funtion. However it is not working.

The code is as below. Am I supposed to use some different Java function?

IPrivateTimesheetView.ICategoriesElement categoryElement;

String wbs ="h";

double d =0;

String sum_hrs ="";

for (int i=0 ; i<wdContext.nodeWorklist().size() ; i++){

wdContext.nodeWorklist().setLeadSelection(i);

categoryElement = wdContext.createCategoriesElement();

wbs = wdContext.currentWorklistElement().getReciever_Wbs_Element();

sum_hrs = wdContext.currentWorklistElement().getSum_Hours();

sum_hrs = sum_hrs.replace(",",".");

if( sum_hrs != null && sum_hrs.trim().length()>0)

d = Double.parseDouble(sum_hrs) ;

categoryElement.setCategoryText(wbs);

categoryElement.setSeries1Value(d);

wdContext.nodeCategories().addElement(categoryElement);

wbs = "";

The error message is

java.lang.NoSuchMethodError: java.lang.String.replace(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Ljava/lang/String;

at com.sastech.app.models.TimesheetView.onActionFindRecord(TimesheetView.java:253)

at com.sastech.app.models.wdp.InternalTimesheetView.wdInvokeEventHandler(InternalTimesheetView.java:365)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.invokeEventHandler(DelegatingView.java:87)

at com.sap.tc.webdynpro.progmodel.controller.Action.fire(Action.java:67)

at com.sap.tc.webdynpro.clientserver.window.WindowPhaseModel.doHandleActionEvent(WindowPhaseModel.java:420)

... 26 more

Can you please help me?

Regards,

S

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Aug 20, 2007 at 11:38 AM

    Hi,

    If you want to pass string then better use replaceAll instead of replace.

    Ashutosh

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 20, 2007 at 11:10 AM

    Hi Stuart,

    see api here http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#replace(char,%20char)

    Hovewer your sum_hrs.replace(",","."); seems to be ok. Please, try to execute the replace outside the "for", probabily you have any strange value.

    Hope this help.

    Vito

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Vito,

      Thanks for reply. I have sorted out the issue by using "replaceAll" in place of "replace".

      Regards,

      S

  • avatar image
    Former Member
    Aug 20, 2007 at 11:05 AM

    Hi.

    The reason is String's class replace method take char as an argument while you are passing String literals as a argument. As an example:

    String str = "7,00";

    str = str.replace(',','.');

    System.out.println(str);

    Regards,

    Nitin

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 20, 2007 at 11:38 AM

    The issue got sorted out by using replaceAll in place of replace. Thanks every one who has replied to the thread for the help.

    Add comment
    10|10000 characters needed characters exceeded