0

In one of my projects, when i calculate the grand total

  shippingDetails.grandTotal = 3.448873577E7

instead of 34488749.7‬ where grandTotal is of type Double

The above object is in my data class and i need to pass as request body for a request, but it fails since it's having scientific notation.

@POST(AppConstants.Network.CONFIRM_PENDING_SHIPPING)
fun confirmPendingShipping(
    @Header("Authorization") token: String,
    @Body shippingItems: RequestConfirmShipping
): Single<ResponsePendingShipping>

I'm passing it as body of post using Retrofit

Manoj Perumarath
  • 9,337
  • 8
  • 56
  • 77
  • which type is the variable, and how exactly are you passing it as request body – Vladyslav Matviienko Jun 18 '19 at 07:08
  • Please add the error as well. – tynn Jun 18 '19 at 07:15
  • in general, `E7` should be accepted by the server, if it expects double value. It is legit double. But if the server is implemented incorrectly, and you can do nothing about it, you may try to format the number as the string – Vladyslav Matviienko Jun 18 '19 at 07:38
  • What's the converter you're using with retrofit and how it is configured? – laalto Jun 18 '19 at 08:05
  • `addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addConverterFactory(ScalarsConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create())` @laalto – Manoj Perumarath Jun 18 '19 at 08:55
  • The API is broken if it doesn't allow scientific notation in JSON numbers but anyway you can configure it: https://stackoverflow.com/questions/11119094/switch-off-scientific-notation-in-gson-double-serialization – laalto Jun 18 '19 at 09:01

0 Answers0