I am having as stream of objects, which can be either type of number like int, short, long, float etc...
What is the best way to convert it into a number. Best way could be something
ToNumber(object oNumber)
// Best magic could be
var number = (somemagic) oNumber;
float operator1 = oNumber is int
? (float)(int)oNumber
: oNumber is long
? (float)(long)oNumber
: oNumber is float
? (float)oNumber
: (float)(int)oNumber;
assuming float will be able to take all number expect double
A float value can be converted to an int value no larger than the input by using the math. floor() function, whereas it can also be converted to an int value which is the smallest integer greater than the input using math. ceil() function.
float(): This function is used to convert any data type to a floating-point number.
Use pandas DataFrame. astype() function to convert column from string/int to float, you can apply this on a specific column or on an entire DataFrame. To cast the data type to 54-bit signed float, you can use numpy. float64 , numpy.
I believe Convert.ToSingle
will be able to handle any "core" numeric type you throw at it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With