Decimal.Parse() vs Convert.ToDecimal() [duplicate] - c#

This question already has answers here:
What's the main difference between int.Parse() and Convert.ToInt32
(13 answers)
Closed 9 years ago.
I would like to know if there is any difference between the captioned two methods?
string str = "14.75";
Console.WriteLine(Decimal.Parse(str));
Console.WriteLine(Convert.ToDecimal(str));
Can anyone please let me know? Thanks.

Decimal.Parse only supports parsing string values, whereas Convert takes other types as well, like, object, int, byte, DateTime etc.

Related

How to write a number in type float? [duplicate]

This question already has answers here:
How do I convert an array of floats to a byte[] and back?
(4 answers)
Closed 9 months ago.
I have the following problem to solve in C#:
Write a number such as 1066018.050 in type float,
the result should be in binary or hexadecimal format.
My question is what are the correct steps I need to follow in order to solve this problem?
You can use BitConverter.GetBytes(float).
float a = (1066018.050F);
var b = BitConverter.GetBytes(a);

explain the two approach String Type Casting In C# [duplicate]

This question already has answers here:
Difference between Convert.ToString() and .ToString()
(19 answers)
variable.ToString() vs. Convert.ToString(variable)
(2 answers)
Closed 7 years ago.
Can anyone please explain me what is the difference between these two string Type Casting method.
Type 1
int i = 90;
string b = i.ToString();
Type 2
int i = 90;
string b = Convert.ToString(i);
I want to know the major difference of using the two different approach. The 1st one is to handle the null value,we can use 'Convert.ToString(); '. And moreover I get to know that '.ToString()' can be override.
Can anyone can explain how. And which one is good to use.
Thanks in Advance.

C# double/decimal always have two decimals [duplicate]

This question already has answers here:
How do I display a decimal value to 2 decimal places?
(19 answers)
Closed 7 years ago.
I need 45.7 to be 45.70
Math.Round(d, 2) have no effect.
Have tried with decimal and double type.
I would appreciate any kind of help.
You need to apply a string format:
string.Format("{0:N2}", 45.7)
Check here for docs on the string formatters

Difference between bool/Boolean, string/String etc [duplicate]

This question already exists:
Closed 12 years ago.
Possible Duplicate:
String vs string in C#
What is the big difference between these datatypes? and were should I use it?
Short answer, there is no difference. They are just alias of each other, see
http://msdn.microsoft.com/en-us/library/ya5y69ds(VS.80).aspx for a complete list.
Have a look at: String vs string in C#

C# Double.ToString() [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Custom numeric format string to always display the sign
To format a double to certain precision in C# I write this:
d.ToString("#0.00");
What if I want to force a the sign to appear..
e.g
+2.54 and -2.54
Hope this will work.
YourDoublenumber.ToString("+#;#");

Categories

Resources