如何比较货币数字格式的值

The code in the picture returning false in both cases of comparison,what values should be given to get the true value

i569546235 回答:如何比较货币数字格式的值

首先,请添加代码而不是图像。很难为图像中的代码提供帮助。

与==的字符串比较可能会或可能不会返回true。使用等于

所以您的代码给出了以下输出

pod [podfile] --version

输出:

public static void main(String[] args) {
    Locale br = new Locale("pt","BR");
    NumberFormat nf = NumberFormat.getCurrencyInstance(br);
    float d = 466.56f;
    System.out.println(nf+" : "+nf.format(d));
    System.out.println(nf.format(d) == "R$ 466,56");  // will return false.
    System.out.println(nf.format(d).equals("R$ 466,56")); // compare string with equals
}
,

问题是,空格有不同的unicode。我键入时获取的空格的Unicode为'\ u0020',但NumberFormat.getCurrencyInstance.format(float)方法返回相同的字符串,但该空格具有Unicode字符'\ u00a0',并且此Unicode字符已从isWhitespace()方法中排除。这就是为什么它为我返回假的原因。

本文链接:https://www.f2er.com/3091269.html

大家都在问