i'm using a NumberTextWatcher for realtime-edit for an EditText and it's working fine for me,
but some users reporting that they got NumberException problem, i think this is because numbers changes in 123,456 in EditText and cant parse to doubles, so i did some change and use Replace("," , "") code but this is not working for some too!
what should i do so this code works for all of my users?
Thanks and Sorry for my Poor English :D
NumberTextWatcher:
public NumberTextWatcher(EditText et)
{
df = new DecimalFormat("#,###");
df.setDecimalSeparatorAlwaysShown(true);
dfnd = new DecimalFormat("#,###");
this.et = et;
hasFractionalPart = false;
}
#SuppressWarnings("unused")
private static final String TAG = "NumberTextWatcher";
#Override
public void afterTextChanged(Editable s)
{
et.removeTextChangedListener(this);
try {
int inilen, endlen;
inilen = et.getText().length();
String v = s.toString().replace(String.valueOf(df.getDecimalFormatSymbols().getGroupingSeparator()), "");
Number n = df.parse(v);
int cp = et.getSelectionStart();
if (hasFractionalPart) {
et.setText(df.format(n));
} else {
et.setText(dfnd.format(n));
}
endlen = et.getText().length();
int sel = (cp + (endlen - inilen));
if (sel > 0 && sel <= et.getText().length()) {
et.setSelection(sel);
} else {
// place cursor at the end?
et.setSelection(et.getText().length() - 1);
}
} catch (NumberFormatException nfe) {
// do nothing?
} catch (ParseException e) {
// do nothing?
}
et.addTextChangedListener(this);
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
if (s.toString().contains(String.valueOf(df.getDecimalFormatSymbols().getDecimalSeparator())))
{
hasFractionalPart = true;
} else {
hasFractionalPart = false;
}
}
And Here is MainActivity:
final EditText amount = (EditText) findViewById(R.id.editText1);
final EditText duration = (EditText) findViewById(R.id.editText2);
final EditText interest = (EditText) findViewById(R.id.editText3);
amount.addTextChangedListener(new NumberTextWatcher(amount));
duration.addTextChangedListener(new NumberTextWatcher(duration));
interest.addTextChangedListener(new NumberTextWatcher(interest));
String amount1 = amount.getText().toString().replaceAll(",", "");
String duration1 = duration.getText().toString().replaceAll(",", "");
String interest1 = interest.getText().toString().replaceAll(",", "");
try{
double i = Double.parseDouble(amount1);
double j = Double.parseDouble(duration1);
double z = Double.parseDouble(interest1);
}
catch(NumberFormatException e){
}
Programs store and operate on numbers in a locale-independent way. Before displaying or printing a number, a program must convert it to a String that is in a locale-sensitive format. For example, in France the number 123456.78 should be formatted as 123 456,78, and in Germany it should appear as 123.456,78. So you can't just replace "," and ".".
The following code is an example on how to convert from double and back using the current currency of a user in the United States.
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Currency;
import java.util.Locale;
public class Test
{
public static void main(String[] args)
{
Locale currentLocale = Locale.getDefault();
Currency currentCurrency = Currency.getInstance(currentLocale);
Double currencyAmount = new Double(9876543.21);
NumberFormat currencyFormatter =
NumberFormat.getCurrencyInstance(currentLocale);
System.out.println(NumberFormat.getNumberInstance(currentLocale));
System.out.println(
currentLocale.getDisplayName() + ", " +
currentCurrency.getDisplayName() + ": " +
currencyFormatter.format(currencyAmount));
try
{
System.out.println(currencyFormatter.parseObject("$9,876,543.21"));
}
catch (ParseException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
What else could you do:
* make sure users are entering properly formatted numbers. For example, you should not see any other chars except numbers , . + - $, etc.
* IF you know the user will ALWAYS enter two decimal digits, for example, 10 dollars would be expressed as 10.00 (or 10,00), then you can safely remove all "," and "." and get the original number by dividing it by 100, but remember to also remove spaces (remember France :) )
Also, check the documentation: http://docs.oracle.com/javase/tutorial/i18n/format/numberFormat.html
The problem is probably that other users might be inputting ill-formatted numbers. So you are just replacing the commas with white spaces. Maybe you should replace all non-digit characters?
amount1 = amount.getText().toString().replaceAll("[^\\d]", "");
Or if you want them to leave the decimal points then use the following:
amount1 = amount.getText().toString().replaceAll("[^\\d.]", "");
Related
I'm creating a Java calculator (only buttons - like T9 keys) in an Android XML Application, and I want to fix the "Cancel" button.
When I click it, I want to cancel the last digit from a String that contains only numbers (or '.', because you can also add '.' to write decimal numbers).
There is a problem: if the user writes an int number (34) and I convert it to double, it becomes 34.0 and, if I cancel the last digit, it cancels the 0.
I also tried with String.substring(start,end), but it doesn't work...
Have you got any suggestions about the cancel handle? Thank you!
This is the function that cancels the last digit.
/* tv -> TextView
- tvResult contains what the user writes and the result when he clicks "=", - tvCalc contains the calc that the user is entering.
For example, if the user writes with the 0-9 buttons and the operator of the operations, in tvCalc there will be "34+50=", and in tvResult "84" */
public void handleCancel(View v) {
//tv -> TextView, tvResult contains what the user writes and the result when he clicks "=", tvCalc contains the calc that the user is entering: for example if user writes with the 0-9 buttons and the operator of the operations, in tvCalc there will be "34+50=", and in tvResult "84"
if (tvResult.length() == 0) {
errorToast = Toast.makeText(MainActivity.this, "Error! There's nothing to cancel!", Toast.LENGTH_LONG);
errorToast.show();
} else {
tvResult.setText(tvResult.toString().substring(0, tvResult.toString().length() - 1))
if (tvCalc.toString().contains("=")) {
tvCalc.setText(tvResult.toString());
operand1 = tvResult.toString();
} else {
tvCalc.setText(tvCalc.toString().substring(0, tvCalc.toString().length() - 1));
if (operator == "") operand1 = tvResult.toString();
else {
operand2 = tvResult.toString();
try {
int conv = Integer.parseInt(tvCalcolo.toString());
operazione = "";
} catch(Exception e) {}
}
}
}
}
The function that adds the choice of the user:
public void userChoice(View v)
{
Button clicked=(Button)findViewById(v.getId());
String choice=clicked.getText().toString();
try
{
int number=Integer.parseInt(choice);
if (operator=="")
{
operand1+=choice;
if (tvCalc.toString().contains("=")) tvCalc.setText(operand1);
} else operand2+=choice;
} catch (Exception e)
{
if (choice.equals('.'))
{
if (operator=="") operand1+=choice;
else operand2+=choice;
} else
{
if (operand2!="")
{
handleEqual(v);
operand1=tvResult.toString();
}
operator=choice;
tvCalc.append(operator);
tvResult.setText("");
return;
}
}
tvCalc.append(choice);
tvResult.append(choice);
}
I edited the function "handleCancel" thanks to Cardinal System:
public void handleCancel (View v)
{
double d;
try
{
d=Double.parseDouble(tvRisultato.toString());
} catch (Exception e)
{
bCanc.setText("Error"); //It's the button 'Cancel'
}
String newVal;
if (d%1==0)
{
int val=(int)d;
newVal=String.valueOf(val);
newVal=newVal.substring(0,newVal.length()-1);
} else
{
newVal=String.valueOf(d);
newVal=newVal.substring(0,newVal.length()-1);
if (newVal.endsWith("."))
{
newVal=newVal.substring(0,newVal.length()-1);
}
}
tvResult.setText(newVal);
if ((tvCalc.toString().contains("+")||tvCalc.toString().contains("-")||tvCalc.toString().contains("*")||tvCalc.toString().contains("/")||tvCalc.toString().contains("^"))&&tvCalc.toString().contains("="))
{
tvCalc.setText(tvResult.toString());
operand1=tvResult.toString();
} else if ((tvCalc.toString().contains("+")||tvCalc.toString().contains("-")||tvCalc.toString().contains("*")||tvCalc.toString().contains("/")||tvCalc.toString().contains("^"))&&!tvCalc.toString().contains("="))
{
if (tvCalc.toString().endsWith("+")||tvCalc.toString().endsWith("-")||tvCalc.toString().endsWith("*")||tvCalc.toString().endsWith("/")||tvCalc.toString().endsWith("^")) operator="";
tvCalc.setText(tvCalc.toString().substring(0,tvCalc.toString().length()-1));
}
}
See if this helps you:
// Let's make it a double so we have something to work with.
double d = Double.parseDouble(tvResult.getText().toString());
String newText;
if (d % 1 == 0) { // See if the number is a whole number
int i = (int) d; // If it is, cast it to an int to get rid of the decimal
newText = String.valueOf(i); // Parse it to a string so we can clip off the end
newText = newText.substring(0, newText.length() - 1); // Clip off the end
} else {
// If it's not a whole number, just parse it to a string.
newText = String.valueOf(d);
newText = newText.substring(0, newText.length() - 1); // Clip off the end
if (newText.endsWith(".")) {
// If the number we clipped off was a tenth, clip off the decimal
newText = newText.substring(0, newText.length() - 1);
}
}
tvResult.setText(newText);
Looks like you could fulfill your requirements at least in two ways:
pattern searching symbols to be removed (something like (.0|\d|+|-|*|/) ) - would not recommend
remembering last input string before new digit/operation is added. F.e. on button . pressed you would remember your current input to calculator to variable and in case you need to cancel, you simply set current input line to that variable
Hope my suggestions were helpfull.
This question already has answers here:
Edit Text shows exception Invalid Int ""
(5 answers)
Closed 6 years ago.
I am getting java.lang.NumberFormatException: Invalid int: error
I believe the declarations are appropriate
I have taken input of numbers in string earlier itself.
The below part only calculates the sum.
Second part is a continuation of 1st part.
Declaration is given below:
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText num1 = (EditText)findViewById(R.id.num1);
final EditText num2 = (EditText)findViewById(R.id.num2);
final EditText resu = (EditText)findViewById(R.id.resu);
resu.setFocusableInTouchMode(false);
resu.setFocusable(false);
resu.setClickable(false);
final Button plus = (Button)findViewById(R.id.plus);
final String n1 = num1.getText().toString();
final String n2 = num2.getText().toString();
On click program:
plus.setOnClickListener(
new Button.OnClickListener() {
public void onClick(View view) {
try{
float sum = Integer.valueOf(n1) + Integer.valueOf(n2);
String a = Float.toString(sum);
a = a.trim();
resu.setText(""+a);
}catch(Exception e){
resu.setText(""+e);
}
}
);
Move the following code inside your onlick() method, because in your oncreate() if the EditText is empty it will return empty String (""), so you need to get the value when the button is clicked, not before it:
final String n1 = num1.getText().toString();
final String n2 = num2.getText().toString();
To:
plus.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) {
try {
final String n1 = num1.getText().toString();
final String n2 = num2.getText().toString();
float sum = Integer.valueOf(n1) + Integer.valueOf(n2);
String a = Float.toString(sum);
a = a.trim();
resu.setText(""+a);
} catch(Exception e) {
resu.setText(""+e);
}
}
});
Problem lies on Integer Object to float primitive type conversion. I think if you give an input a Whole Number then your code should work fine. code
float sum = Integer.valueOf(n1) + Integer.valueOf(n2);
But if it's not a whole Number then inorder to incounter NumberFormatException you're failing to convert String into your appropriate primitive Data type.
And also check for empty String ("") in n1 and n2 by if(n1=="")
plus.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) {
try
{
final String n1 = num1.getText().toString();
final String n2 = num2.getText().toString();
if(n1==""){
n1="0";
}
float sum = Float.valueOf(n1) + Float.valueOf(n2);
String a = Float.toString(sum);
a = a.trim();
resu.setText(""+a);
}
catch(Exception e)
{
resu.setText(""+e);
}
}
});
I'm working in an Android application and i want to create a decimal mask for editText in android. I want a mask like a maskMoney jQuery plugin. But in some cases my number will have 2 decimal places, 3 decimal places or will be a integer. I want do something like this:
When the EditText is created, come with a default value: 00.01
If user press the number 2, the result should be: 00.12
If user press the number 3, the result should be: 01.23
If user press the number 4, the result should be: 12.34
If user press the number 5, the result should be: 123.45
If user press the number 6, the result should be: 1,234.56
What's the best way to do that?
I resolved with this:
public static TextWatcher amount(final EditText editText, final String metric) {
return new TextWatcher() {
String current = "";
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (!s.toString().equals(current)) {
editText.removeTextChangedListener(this);
String cleanString = s.toString();
if (count != 0) {
String substr = cleanString.substring(cleanString.length() - 2);
if (substr.contains(".") || substr.contains(",")) {
cleanString += "0";
}
}
cleanString = cleanString.replaceAll("[,.]", "");
double parsed = Double.parseDouble(cleanString);
DecimalFormat df = new DecimalFormat("0.00");
String formatted = df.format((parsed / 100));
current = formatted;
editText.setText(formatted);
editText.setSelection(formatted.length());
editText.addTextChangedListener(this);
}
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void afterTextChanged(Editable s) {}
};
}
Do you know of any method to make sure users can only enter figures with a maximum number of decimals.
I'm not sure how to address this problem. In the MS SQL database I'm going to send data from my app I've got columns with this type decimal(8,3)
Now considering the data type of the column that's finally going to store the value I want to validate in Android, I've considered these two cases:
If the user enters a number with no decimals, the maximum number of digits must be 8
If the user enters a number with decimals, the maximum number of digits must be 8 (including the digits to the right of the decimal point)
Now I'm sure about the first case, but not so much about the second. Is it right to keep the number of maximum digits fixed(for example, always 8)? Or should I consider allowing a maximum of 8 digits to the left and 3 to the right of the decimal point?
Either way this is what I've been trying in Android:
mQuantityEditText.addTextChangedListener(new TextWatcher() {
#Override
public void afterTextChanged(Editable s) {
String str = mQuantityEditText.getText().toString();
DecimalFormat format = (DecimalFormat) DecimalFormat
.getInstance();
DecimalFormatSymbols symbols = format.getDecimalFormatSymbols();
char sep = symbols.getDecimalSeparator();
int indexOFdec = str.indexOf(sep);
if (indexOFdec >= 0) {
if (str.substring(indexOFdec, str.length() - 1).length() > 3) {
s.replace(0, s.length(),
str.substring(0, str.length() - 1));
}
}
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
});
Even though, the above code handles the maximum number of decimal places. It does not limit the total number of digits allowed in the EditText.
Do you think you could help me improve my code so that it handles both the maximum number of decimal places and the total number of digits allowed in a EditText (considering both numbers to the left and to the right of the decimal point)
EDIT
Well, now I'm trying what João Sousa suggested and here's what I've tried:
1) I defined a class that implements InputFilter
public class NumberInputFilter implements InputFilter {
private Pattern mPattern;
public NumberInputFilter(int precision, int scale) {
String pattern="^\\-?(\\d{0," + (precision-scale) + "}|\\d{0," + (precision-scale) + "}\\.\\d{0," + scale + "})$";
this.mPattern=Pattern.compile(pattern);
}
#Override
public CharSequence filter(CharSequence source, int start, int end, Spanned destination, int destinationStart, int destinationEnd) {
if (end > start) {
// adding: filter
// build the resulting text
String destinationString = destination.toString();
String resultingTxt = destinationString.substring(0, destinationStart) + source.subSequence(start, end) + destinationString.substring(destinationEnd);
// return null to accept the input or empty to reject it
return resultingTxt.matches(this.mPattern.toString()) ? null : "";
}
// removing: always accept
return null;
}
}
2) Tried to use the class like this :
mQuantityEditText.setFilters(new InputFilter[] { new NumberInputFilter(8,3)} );
I would go for a filter in the edit text itself with the power of regex. First the regex expression:
^\-?(\d{0,5}|\d{0,5}\.\d{0,3})$
Maybe there are multiple ways to improve this expression, but this does trick.
And now just set an input filter in the edittext, like this:
final String regex = "^\-?(\d{0,5}|\d{0,5}\.\d{0,3})$";
((EditText)rootView.findViewById(R.id.editText1)).setFilters(new InputFilter[] {
new InputFilter() {
#Override
public CharSequence filter(CharSequence source, int start, int end, Spanned destination, int destinationStart, int destinationEnd) {
if (end > start) {
// adding: filter
// build the resulting text
String destinationString = destination.toString();
String resultingTxt = destinationString.substring(0, destinationStart) + source.subSequence(start, end) + destinationString.substring(destinationEnd);
// return null to accept the input or empty to reject it
return resultingTxt.matches(regex) ? null : "";
}
// removing: always accept
return null;
}
}
});
Btw, I just tested this code and what it does is:
The user can enter a maximum of 8 digits;
As soon as the user enters a '.', the maximum decimal digits allowed are 8.
Did I correctly understand the problem you described?
-- EDIT
Ok, I was almost there. From what I understand, decimal(8,3) means at most 8 digits including digits to the left or right of the decimal point, ranging from -99999.999 to 99999.999.
At least that's what I understand from this sentence Standard SQL requires that DECIMAL(5,2) be able to store any value with five digits and two decimals, so values that can be stored in the salary column range from -999.99 to 999.99. Even though it's from the MySQL documentation the MSSQL docs seem to do the same.
I have answser for you, me also suffered lot in this kind of situation.:D :P
I have implemented this for maximum of 4 digits to the left and 2 to the right of the decimal point ex: 4444.99
so small changes need to implement what i did:
Need to do following changes
1) copy CustomTextWatcher.java to track input of editText.
import java.text.NumberFormat;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.EditText;
public class CustomTextWatcher implements TextWatcher {
private NumberFormat nf = NumberFormat.getNumberInstance();
private EditText et;
private String tmp = "";
private int moveCaretTo;
private static final int INTEGER_CONSTRAINT = 4;
private static final int FRACTION_CONSTRAINT = 2;
private static final int MAX_LENGTH = INTEGER_CONSTRAINT
+ FRACTION_CONSTRAINT + 1;
public CustomTextWatcher(EditText et) {
this.et = et;
nf.setMaximumIntegerDigits(INTEGER_CONSTRAINT);
nf.setMaximumFractionDigits(FRACTION_CONSTRAINT);
nf.setGroupingUsed(false);
}
public int countOccurrences(String str, char c) {
int count = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == c) {
count++;
}
}
return count;
}
#Override
public void afterTextChanged(Editable s) {
et.removeTextChangedListener(this); // remove to prevent stackoverflow
String ss = s.toString();
int len = ss.length();
int dots = countOccurrences(ss, '.');
boolean shouldParse = dots <= 1
&& (dots == 0 ? len != (INTEGER_CONSTRAINT + 1)
: len < (MAX_LENGTH + 1));
if (shouldParse) {
if (len > 1 && ss.lastIndexOf(".") != len - 1) {
try {
if (ss.contains(".")) {
String[] integerFractionStrings = ss.split("\\.");
Log.v("Check SS ", ss);
Log.v("second string", "Found"
+ integerFractionStrings.length);
if (integerFractionStrings.length > 1) {
Log.v("integerFractionStrings",
integerFractionStrings[1]);
if (integerFractionStrings[1].length() == 1
&& integerFractionStrings[1].charAt(0) == '0') {
et.setText(ss);
Log.v("second string", "size 1");
} else {
Log.v("second string", "> 1");
Double d = Double.parseDouble(ss);
if (d != null) {
et.setText(nf.format(d));
}
}
}
} else {
Log.v("First string", "No dot");
Double d = Double.parseDouble(ss);
if (d != null) {
et.setText(nf.format(d));
}
}
} catch (NumberFormatException e) {
}
}
} else {
Log.v("second string", "size 1");
et.setText(tmp);
}
et.addTextChangedListener(this); // reset listener
// tried to fix caret positioning after key type:
if (et.getText().toString().length() > 0) {
if (dots == 0 && len >= INTEGER_CONSTRAINT
&& moveCaretTo > INTEGER_CONSTRAINT) {
moveCaretTo = INTEGER_CONSTRAINT;
} else if (dots > 0 && len >= (MAX_LENGTH)
&& moveCaretTo > (MAX_LENGTH)) {
moveCaretTo = MAX_LENGTH;
}
try {
et.setSelection(et.getText().toString().length());
// et.setSelection(moveCaretTo); <- almost had it :))
} catch (Exception e) {
}
}
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
moveCaretTo = et.getSelectionEnd();
tmp = s.toString();
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
int length = et.getText().toString().length();
if (length > 0) {
moveCaretTo = start + count - before;
}
}
}
2) set this class to check your editText by following.
EditText review_food_Price;
review_food_Price = (EditText) findViewById(R.id.food_Price);
review_food_Price.setRawInputType(InputType.TYPE_CLASS_NUMBER
| InputType.TYPE_NUMBER_FLAG_DECIMAL);
review_food_Price.addTextChangedListener(new CustomTextWatcher(
review_food_Price));
Hope you can convert my code according to your need.
The problem that you describe is precisely what a Masked EditText is meant to be used for. :)
I'm using a TextWatcher for editing values while entering in EditText
here is my TextWatcher
public class NumberTextWatcher implements TextWatcher {
private DecimalFormat df;
private DecimalFormat dfnd;
private boolean hasFractionalPart;
private EditText et;
public NumberTextWatcher(EditText et)
{
df = new DecimalFormat("#,###");
df.setDecimalSeparatorAlwaysShown(true);
dfnd = new DecimalFormat("#,###");
this.et = et;
hasFractionalPart = false;
}
#SuppressWarnings("unused")
private static final String TAG = "NumberTextWatcher";
#Override
public void afterTextChanged(Editable s)
{
et.removeTextChangedListener(this);
try {
int inilen, endlen;
inilen = et.getText().length();
String v = s.toString().replace(String.valueOf(df.getDecimalFormatSymbols().getGroupingSeparator()), "");
Number n = df.parse(v);
int cp = et.getSelectionStart();
if (hasFractionalPart) {
et.setText(df.format(n));
} else {
et.setText(dfnd.format(n));
}
endlen = et.getText().length();
int sel = (cp + (endlen - inilen));
if (sel > 0 && sel <= et.getText().length()) {
et.setSelection(sel);
} else {
// place cursor at the end?
et.setSelection(et.getText().length() - 1);
}
} catch (NumberFormatException nfe) {
// do nothing?
} catch (ParseException e) {
// do nothing?
}
et.addTextChangedListener(this);
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
if (s.toString().contains(String.valueOf(df.getDecimalFormatSymbols().getDecimalSeparator())))
{
hasFractionalPart = true;
} else {
hasFractionalPart = false;
}
}
after that, I try to Parse the values to doubles using this code :
String amount1 = amount.getText().toString().replaceAll("[^\\d]", "");
String duration1 = duration.getText().toString().replaceAll("[^\\d]", "");
String interest1 = interest.getText().toString().replaceAll("[^\\d]", "");
But the problem i have is that when Device Default language is not English, it can parse the string to Doubles, so i think i set US Locale for editTexts! is this possible? if not, what should i do in order to be able to parse values to doubles?
DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.US);
When you have control over the back-end I find it easiest to deal with what language you are expecting and have done extensive tests on. Therefore, when handling file IO on files that I have internally, I always call the call that you have at the end of your comment there before any file creation code is performed. In my case it would be
final DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getInstance(Locale.ENGLISH); //Format our data to two decimal places for brightness change.
String stringFormat = "#0.00";
decimalFormat.applyPattern(stringFormat);
decimalFormat.format(dataString);
Then, no matter what language the device is actually set to, you are always dealing with the locale that you are accustomed to. And this will aide in handling other languages that might use different number formats for instance in this case since I was handling numerics. Since you are dealing with doubles you might be approaching this numeric translation issue. But if you are dealing with inputs from an EditText, this particular approach that was only on my back-end might not be applicable. But I thought communicating my approach might still be somewhat helpful; hopefully anyways. Doesn't hurt to share.