📜  Java中的 DecimalFormat setNegativePrefix() 方法

📅  最后修改于: 2022-05-13 01:54:26.703000             🧑  作者: Mango

Java中的 DecimalFormat setNegativePrefix() 方法

Java中DecimalFormat类的setNegativePrefix()方法用于设置这个DecimalFormat实例的负值。

语法

public void setNegativePrefix(String newValue)

参数:此方法的单个参数 newValue 是要设置为此 DecimalFormat 实例的负前缀的新值。

返回值:此方法不返回任何值。

下面的程序说明了上述方法:

// Java program to illustrate the
// setNegativePrefix() method
  
import java.text.DecimalFormat;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Create a DecimalFormat instance
        DecimalFormat deciFormat = new DecimalFormat();
  
        // Set a negative prefix value
        deciFormat.setNegativePrefix("negative");
  
        // Print a number with negative prefix set
        System.out.println(deciFormat.format(-123.45));
    }
}
输出:
negative123.45

参考:https: Java Java.lang.String)