0
Java言語でのJS toFixed(2)メソッドの同義語は何ですか? オプションはDecimalFormatのみですか?Java toFixed(2)メソッドこのようなjs
Java言語でのJS toFixed(2)メソッドの同義語は何ですか? オプションはDecimalFormatのみですか?Java toFixed(2)メソッドこのようなjs
ありnoneですが、あなたは、代替としてこれを行うことができます:
/**
* Shortens a float to a specified length
* @param num The float to shorten
* @param to The length
* @return the shortened version
**/
public static String toFixed(float num, int to){
//Split at the decimal point
String[] s = String.valueOf(num).split("[.]");
//Combine the two so and shorten the second
String ending = s[1].substring(0, ((s[1].length() > to) ? to : s[1].length()));
return s[0] + '.' + ending;
}
これしないのラウンドかかわら[?私はJavaで小数点以下2桁のダブルを丸めるにはどうすればよい]の
返されてくれてありがとう、私はDecimalFormatを使うことにしました。他のものよりも役に立つ –
可能な重複(http://stackoverflow.com/questions/5710394/how-do-i-round-a-double-to-two-decimal-places-in-java) –
またはhttp://stackoverflow.com/questions/2538787/how-to-display-of-float-data-with-2-decimal-places-in-java –
ええ、私は最初のものを使用しました –