Search code examples
javarestjersey

Java Rest send double values


Here in my Java Jersey Rest service, for an update method, the value "money" is represented as long in server. And valid values are between 30.00 and 500.00

Which one is more standart approach? should I force the client to send money value as 30.00 with a dot and parse manually in server than make it double/long. Or sent as 3000 and parse that way. Or there is already a way to this in java/jerseylibrary.

@PUT
@Path("/money")
@Consumes("text/plain)
public void updateThreshold(String threshold) {

*//check value and update in server*
}

note: I don't want to use parametrized requests to set parameter type as double


Solution

  • It will be much easier to save all data in cents. Its avoid you from some possible problems with rounding, and different data formats (in such countries used ',' as separator, in other '.'), Also storing and sorting by int value in DB more better too.