Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed incorrect cast getting float from array #604

Merged
merged 1 commit into from May 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/org/json/JSONArray.java
Expand Up @@ -326,7 +326,7 @@ public double getDouble(int index) throws JSONException {
public float getFloat(int index) throws JSONException {
final Object object = this.get(index);
if(object instanceof Number) {
return ((Float)object).floatValue();
return ((Number)object).floatValue();
}
try {
return Float.parseFloat(object.toString());
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/org/json/junit/JSONArrayTest.java
Expand Up @@ -364,6 +364,8 @@ public void getArrayValues() {
new Double(23.45e-4).equals(jsonArray.getDouble(5)));
assertTrue("Array string double",
new Double(23.45).equals(jsonArray.getDouble(6)));
assertTrue("Array double can be float",
new Float(23.45e-4f).equals(jsonArray.getFloat(5)));
// ints
assertTrue("Array value int",
new Integer(42).equals(jsonArray.getInt(7)));
Expand Down