Skip to content

Commit 5b54ee3

Browse files
Make Py JSON float_precision apply to both float and double fields.
PiperOrigin-RevId: 747969948
1 parent 81482af commit 5b54ee3

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

python/google/protobuf/json_format.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,10 @@ def _FieldToJsonObject(self, field, value):
316316
return _INFINITY
317317
if math.isnan(value):
318318
return _NAN
319-
if field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_FLOAT:
320-
if self.float_format:
321-
return float(format(value, self.float_format))
322-
else:
323-
return type_checkers.ToShortestFloat(value)
319+
if self.float_format:
320+
return float(format(value, self.float_format))
321+
elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_FLOAT:
322+
return type_checkers.ToShortestFloat(value)
324323

325324
return value
326325

0 commit comments

Comments
 (0)