mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-02 11:05:28 -04:00
Merge pull request #604 from ianlovejoy/master
Fixed incorrect cast getting float from array
This commit is contained in:
commit
143db39d27
@ -326,7 +326,7 @@ public class JSONArray implements Iterable<Object> {
|
|||||||
public float getFloat(int index) throws JSONException {
|
public float getFloat(int index) throws JSONException {
|
||||||
final Object object = this.get(index);
|
final Object object = this.get(index);
|
||||||
if(object instanceof Number) {
|
if(object instanceof Number) {
|
||||||
return ((Float)object).floatValue();
|
return ((Number)object).floatValue();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return Float.parseFloat(object.toString());
|
return Float.parseFloat(object.toString());
|
||||||
|
@ -364,6 +364,8 @@ public class JSONArrayTest {
|
|||||||
new Double(23.45e-4).equals(jsonArray.getDouble(5)));
|
new Double(23.45e-4).equals(jsonArray.getDouble(5)));
|
||||||
assertTrue("Array string double",
|
assertTrue("Array string double",
|
||||||
new Double(23.45).equals(jsonArray.getDouble(6)));
|
new Double(23.45).equals(jsonArray.getDouble(6)));
|
||||||
|
assertTrue("Array double can be float",
|
||||||
|
new Float(23.45e-4f).equals(jsonArray.getFloat(5)));
|
||||||
// ints
|
// ints
|
||||||
assertTrue("Array value int",
|
assertTrue("Array value int",
|
||||||
new Integer(42).equals(jsonArray.getInt(7)));
|
new Integer(42).equals(jsonArray.getInt(7)));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user