In Android,
I going to store 8 digits in Sqlite but when i retrieved values from edittext to Float/Double then value was displaying with specific number format ie. "E" or some time add "." in values.
Edit text value is : 99989888
Result is : 9.998989
How i can resolve this issue?
I can't use BigDecimal because it's not supported by Sqlite and > operator.
You can try using long instead
You can use TEXT representation of BigDecimal and convert it in/out when you need it. Another aproach is here
Related
I have this string:
$V{Formatter}.format(new Double($F{quantita}.replaceAll(",",".")))+" " + $F{unitaDiMisura}
that serves to display a number on a document, based on the value that the user digits on his control panel.
With this string, if the user digits "1", in the document appears "1,00".
What do I need to do if I don't want the decimals to be displayed?
Example: if the user digits "1", I want that in the document is displayed "1".
Sorry if something is not understandable, I'm not a developer...
Thanks in advance to everyone who will help.
You have to convert the double value to integer type.
I assume $F{quantita} contains the double value (in String) then,
String.valueOf(Double.valueOf($F{quantita}).intValue())
Above line can be split down like below.
Create a Double value from String.
Double value = Double.valueOf($F{quantita});
extract the Integer portion from double value.
Integer intValue = value.intValue();
Convert to String using toString().
intValue.toString();
Thanks guys! I was in need of the same exact thing :D I guess we are having troubles editing the same software (Fattura24).
I wanted to ask #Dinesh how would I then divide this integer by a set number?
E.g. I have $F{quantita} (which contains the double value if not converted to integer) and I need to display the result of its division by 4. So the output has to be the integer result of $F{quantita} /4. How can I achieve this? Thank you for your help
I successfully added multiple locales to my app and figured out how to switch between them, but the problem is after I switch the locale everything works all right except numbers
For example if I switch to Persian numbers will remain 123 which is wrong and should be switched to ١٢٣.
I can't use String.format(number) cause most of my numbers are included in Strings. Anyone can help me out here?
if you want to translate number as well you must not bind it as a string , you must set it as float or int
<string name="numberRes">%d</string>
textview.setText(String.format(R.string.numberRes,numberValue))
numberValue must be an integer in case of float replace %d with %f
in case all numbers in string format use
textview.setText(String.format(R.string.numberRes,Integer.valueOf(numberValue)))
and be careful of NumberFormatException if your string has a wrong number format
Best solution I found is a hacky way to force a numeral font in Persian/Arabic locales!
You have to create multiple font.xml files and put them in res/font then use locale based themes to assign related font to android:fontFamily.
Here is the result:
font/font-en.xml
font/font-ar.xml
font/font-fa.xml
values-en/themes.xml
values-ar/themes.xml
values-fa/themes.xml
I have a big number in a database; in this case, 10,000,000,000. Whenever I use that information for something, like sending a message with it, instead of 10,000,000,000, it says 1E10, and I really do not want that.
Can I avoid that in any way?
If I go to the database, the value is 10,000,000,000.
It's the same number, just represented in scientific notation.
Since you don't describe how you are storing the value, you can use DecimalFormat#getNumberInstance to help format it to one that doesn't contain the scientific notation.
double foo = 10000000000L;
System.out.println(foo);
System.out.println(DecimalFormat.getIntegerInstance().format(foo));
This outputs:
1.0E10
10,000,000,000
I'm creating an Android app, and I'm reading some coordinates from a text file.
I'm using Integer.parseInt(xCoordinateStringFromFile) to convert the X coordinates to integers, and in the same way with the Y coordinates.
When I run the app, I get an error on that line, which looks like this:
BridgeData data = new BridgeData(
elements[0],
elements[1],
Integer.parseInt(elements[2]),
Integer.parseInt(elements[3]),
Integer.parseInt(elements[4]),
new GeoPos(Integer.parseInt(elements[5].split(",")[0]), Integer.parseInt(elements[5].split(",")[1])),
new GeoPos(Integer.parseInt(elements[6].split(",")[0]), Integer.parseInt(elements[6].split(",")[1])),
Integer.parseInt(elements[7]),
Integer.parseInt(elements[8])
);
The variable elements is a String array created by splitting the current line on every ;.
The "main" error is:
java.lang.NumberFormatException: Invalid int: "3546504756"
I wonder what this means, and how I can solve it.
Error just means that java is not able to convert the String that you are trying to use in your call to Integer.pasrseInt as that number is out of range of an integer.
You should be using Long.parseLong as 3546504756 number is out of range of an integer.
Make sure post that your BridgeData constructor accepts long as a parameter instead of integer.
Revising the concept of data type and their size might help you
http://www.tutorialspoint.com/java/java_basic_datatypes.htm
In Java, an int is 32 bits, which is enough to store numbers up to just over 2 billion. The number you were trying to read was an invalid int because it was too big.
I would seriously question the design of whatever you are doing, if you have coordinates with values of over a billion. But if you really need such big numbers, use long in place of int in your BridgeData class, and Long.parseLong in place of Integer.parseInt in the code that you quoted.
The range of int value can be lies between -2,147,483,648 to 2,147,483,647 and you are providing it more than that thats why it giving numberformatexception
You have to store the value in either long or other more range premetive type.
You can find more about java premetive data type range and value here
I'm using java and Apache derby to create a project that deals with big numbers. Everything is going fine except when i store big numbers.
For eg. when i save 1000000000 through my java class to a derby table, it automatically becomes 1.0E9. When this value is retrieved in another form it is displayed like 1.0E9. How can I stop this? I'm using float data type to do this.
In other words, how can I save 1000000000 as 1000000000 and not 1.0E9
Like above said you could use a BigInteger or you could just covert 1.0E9 to what the number actually is. 1.0 x 10^9.
1.0e9 is the same as 1000000000; it's just a representation issue. You just have to apply the proper formatters when transforming it to a string.
Two things that would make this easier are to use the NUMERIC column type in Derby, and also use either BigDecimal or BigInteger data types in your Java code, or possibly a long if you're confident that the long can hold the values in your problem domain.
import java.math.BigInteger;
//...
//...
//...
BigInteger store = new BigInteger("1000000000");