parseLong Numberformat exception 7.7

I'm retrieving a number from EditText:

long org=0;
String EnteredOrgAmount=amount.getText().toString();

if(!EnteredOrgAmount.equalsIgnoreCase("")) {
    org=Long.parseLong(EnteredOrgAmount);
}

This works fine, until I enter 7.7 for example, the I get a numberFormatException. I can't use the comma, since I declared the EditText in XML as: android:inputType="numberDecimal"

Is there a way to work around this issue?

Answers


Instead of parsing in Long parse in Double and if you have need only long value then parse in double and store in long value

double org=0;
String EnteredOrgAmount=amount.getText().toString();

if(!EnteredOrgAmount.equalsIgnoreCase("")) {
    org=Double.parseDouble(EnteredOrgAmount);
}

For long just declare org as long instead of double

long org=0;
String EnteredOrgAmount=amount.getText().toString();

if(!EnteredOrgAmount.equalsIgnoreCase("")) {
    org=(long)Double.parseDouble(EnteredOrgAmount);
}

Need Your Help

What does “Entity Tracked by Context” mean in Entity Framework

entity-framework entity-framework-4

I am reading this E.F. Team Blog's this series http://blogs.msdn.com/b/adonet/archive/2011/01/27/using-dbcontext-in-ef-feature-ctp5-part-1-introduction-and-model.aspx

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.