Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6704667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:18:54+00:00 2026-05-26T07:18:54+00:00

I am fighting with making my app language dependent. The user needs to enter

  • 0

I am fighting with making my app language dependent. The user needs to enter a float. I am using a EditText to display the current value and allow editing.
To prepare I coded:

st = String.format("%.2f", myFloat);
edTxt = (EditText) findViewById(R.id.myEditText);
edTxt.setText(st, TextView.BufferType.EDITABLE);
edTxt.selectAll();

Now the user is presented the value. If in Settings of my device, I set my language to Deutsch (German) an float value of 2.80 is displayed as 2,80. On onPause of the activity I retrieve the value and convert it from string to float – and get a NumberFormatException error because of the comma.
Should be easy I thought, I just need to replace the comma by a dot, and coded:

String st ="";
st = edTxt.getText().toString();
st.replace(",", ".");
try{
    float minV = Float.valueOf(st);
} catch (NumberFormatException nfe){
    mShowAToast("NumberFormatException: " + st);
}

And surprise: The app runs into the catch and the toast shows st as “2,80” instead of “2.80”, st.replace didn’t do its job.
(probably it did, but)
Do I oversee anything?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:18:55+00:00Added an answer on May 26, 2026 at 7:18 am

    If you have an float value that use ‘,’ as decimal separator. You can parse it using a Locale class. Check the following code.

    public static void main(String[] args) {
        try {
            // Number and NumberFormat are in java.text.*;
            Number numberG = NumberFormat.getNumberInstance(java.util.Locale.GERMAN).parse("-1.234,56");
            if (numberG instanceof Double) {
                System.out.println(">" + numberG.doubleValue());
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    

    It will print:

    >-1234.56
    

    So instead of use java.util.Locale.GERMAN you can use the defaul locale: java.util.Locale.getDefault() of your JVM.

    About the replace function of String I have compared the specfication of Android API and Oracle JDK and both are the same. So I think it must return what you expected. Just in case I have tried the folowing in my JDK:

        String value = "-1.234,56";
        System.out.println(value.replace(',', '.'));
        System.out.println(value.replace(",", "."));
    

    And both are printing: -1.234.56

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a fighting game in Flash and while I have everything running,
I'm fighting with OSX's packageMaker as it doesn't allow me to create a '.pkg'.
I'm using very tricky fighting methods :) to make a string like Fi?le*/ Name
I'm making a fighting game in Java for a project and trying to get
I'm making a turn based rpg game with some multiplayer functions using GAE. I
I'm making a fighting game, and I am trying to keep a queue of
Still fighting with templates. In this example, despite the fact that is copied straight
Okay still fighting with doing some SqlCacheDependecy in my Asp.net MVC application I got
We've been fighting with HAProxy for a few days now in Amazon EC2; the
I'm fighting here with System.Printing namespace of .net framework. And what i always saw

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.