1

ここで私の Java Jersey Rest サービスでは、更新メソッドの場合、値「money」はサーバーで long として表されます。有効な値は 30.00 から 500.00 の間です

どちらがより標準的なアプローチですか? クライアントにドットを使用して 30.00 として金額を送信させ、サーバーで手動で解析するように強制する必要があります。または 3000 として送信し、そのように解析します。または、Java/jerseylibrary でこれを行う方法が既にあります。

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

*//check value and update in server*
}

注: パラメータ タイプを double に設定するためにパラメータ化されたリクエストを使用したくありません

4

2 に答える 2

1

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.

于 2013-01-04T14:59:11.270 に答える
0

セントを使用できない場合は、ユーザーに文字列を渡させてから Float.parseFloat(floatval) を使用してみてはどうでしょうか。

30.98、30、30.00 などの文字列入力で機能します。例:

    String amount1 = "30.98";
    String amount2 = "30";
    String amount3 = "30.00";
    System.out.println("Amount :: " + Float.parseFloat(amount1));
    System.out.println("Amount :: " + Float.parseFloat(amount2));
    System.out.println("Amount :: " + Float.parseFloat(amount3));

出力:

Amount :: 30.98
Amount :: 30.0
Amount :: 30.0
于 2013-01-04T15:21:37.180 に答える