Why we don´t need suffix after conversion but during declaration we
need it?
By default and by C# specifications every number has a floating point
will consider as a Double
variable so you need to use an F
suffix to create a literal for this type.
// 3.14 is considered a double variable by the compiler so it gives you an error
float myFloat = 3.14;
You might ask why a double variable with value 3.14
cannot be assigned or cast into a float variable?
http://net-informations.com/q/faq/float.html
The Decimal, Double, and Float variable types are different in the way
that they store the values. Precision is the main difference where
float is a single precision (32 bit) floating point data type, double
is a double precision (64 bit) floating point data type and decimal is
a 128-bit floating point data type.
Float - 32 bit (7 digits) Double - 64 bit (15-16 digits)
The main difference is Floats and Doubles are binary floating point
types and a Decimal will store the value as a floating decimal point
type. So Decimals have much higher precision and are usually used
within monetary (financial) applications that require a high degree of
accuracy. But in performance wise Decimals are slower than double and
float types.
You can read this answer as well.
And about Parse
method:
float.Parse
only requires a valid string which means only a string includes [0-9
], sign character and the decimal point ( vary by culture for eg [,/.
]).
So you only need to get rid of any non-valid chars from your strings then parse it.