String Formatter in GWT

前端 未结 12 654
生来不讨喜
生来不讨喜 2021-02-03 18:59

How do I format my string in GWT?

I made a method

  Formatter format = new Formatter();
    int matches = 0;
    Formatter formattedString = format.forma         


        
12条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-03 19:56

    See the official page on GWT date and number formatting.

    They suggest the following:

    myNum decimal = 33.23232;
    myString = NumberFormat.getFormat("#.00").format(decimal);
    

    It is best to use their supported, optimized methods, than to cook up your own non-optimal method. Their compiler will be optimizing them all to nearly the same thing anyway in the end.

提交回复
热议问题