What string should I pass to Java lang.Long. Parselong() to return Nan?

Unfortunately, I can't use anything like long Nan, because the string is actually the return value from different C modules Is there a string I can pass to parselong() to return a Nan?

Solution

No long Nan – you're confused

For double Nan, how about this:

public double myParseDouble(String s)
{
   double result;
   try
   {
      result = Double.parseDouble(s);
   }
   catch (NumberFormatException nfe)
   {
      result = Double.NaN;
   }
   return result;
}

(edit: the obvious way is to pass in any invalid double string, such as an empty string or Nan)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>