Hello,
Is there a number extractor somewhere in the standard lib?
I need an extractor that matches an object of numeric type (Float, Double, Int, etc) and gives me the approximate value as Double.
Yeah, I could roll my own.
Best, Oliver
Hello,
Is there a number extractor somewhere in the standard lib?
I need an extractor that matches an object of numeric type (Float, Double, Int, etc) and gives me the approximate value as Double.
Yeah, I could roll my own.
Best, Oliver
I don’t think there’s an extractor. Does case n: Number => n.doubleValue
work for you?
Hello,
Thanks for the idea. I’m thinking hard whether that is guaranteed to
work. I suppose if a reference of type Any is being matched and it is a
number, it must be boxed and then it is a subtype of Number. Or could some
compiler optimization break it?
It would be so nice if Scala had a Number type that is a real supertype
of its numeric value types.
Best, Oliver