Does Decimal.Parse() support scientific notation? [duplicate] - c#

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
C# Parse a Number from Exponential Notation
I currently have:
decimal value = Decimal.Parse(dataRow["column"].ToString());
There is some data in the backend that is in scientific notation (ie 3.2661758893885E-05) and which is causing a FormatException on the parse. Is there an easy way to do this?

Try something like this:
Decimal.Parse(strExpression, System.Globalization.NumberStyles.AllowExponent));

Related

Correct way to precisely round decimals in C# [duplicate]

This question already has answers here:
How do I make it round off instead of always round down?
(2 answers)
How to round a decimal up?
(6 answers)
Closed 5 months ago.
This is my code:
decimal test1 = 190.5m;
decimal test2 = 191.5m;
var testResult1 = Math.Round(test1, 0); // =190 It should be 191!!!!
var testResult2 = Math.Round(test2, 0); // =192 Correct.
Is there a way I could get the correct result? Maybe another library instead of System.Math?
This is by design. Albeit not what we have grown up with.
Find how you manage to round the way you expect here:
https://learn.microsoft.com/en-us/dotnet/api/system.midpointrounding?redirectedfrom=MSDN&view=net-6.0
For a bit more reading and background, have a browse through some of the answers here:
Why does .NET use banker's rounding as default?

C# convert string value to display with thousands separators [duplicate]

This question already has answers here:
How can I convert String to Int?
(31 answers)
String.Format an integer to use a thousands separator with decimal value in danish culture
(5 answers)
How would I separate thousands with space in C#
(6 answers)
Closed 2 years ago.
I'm receiving a string value (for example "331000110.00") and I want to convert it so it has thousands separators (I want to have something like this: 331 000 110.00). Important thing is that I want this field to stay as a string. Anyone can help me with this?

Convert decimal (2.75) to time (2:45) [duplicate]

This question already has answers here:
C# String Format for hours and minutes from decimal
(3 answers)
Closed 9 years ago.
If I have a double like 2.75, is there a way in .Net to format it as '2:45'
If it is for example, 2.75555555555, it should round it to the nearest minute.
I would not mind coding this myself, but I am wondering if .Net can. I checked ToString but did not find anything.
Thanks
Use TimeSpan and its ToString formatter:
TimeSpan timespan = TimeSpan.FromHours(2.75);
string output = timespan.ToString("h\\:mm");
For example
TimeSpan.FromHours(2.75555).ToString("h\\:mm")
outputs
2:45

String conversion C# [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Convert from scientific notation string to float in C#
Is it there an build-in function which converts string in format "2.71e+006" to a number or I have to write my custom algorithm?
The Decimal Parse method has an overload you can use:
decimal d = Decimal.Parse("2.71e+006", System.Globalization.NumberStyles.Float);
You can also do the same for a Double.

How to display a customized code in C# & DevExexpress TextEditor with mask [duplicate]

This question already has answers here:
Is it possible to pad integers with zeros using regular expressions?
(2 answers)
Closed 9 years ago.
I am trying to display a code like ABC/DEF/00012 or ABC/EDF/01234 or ABC/DEF/00009
I use RegEx mask \w{3}/\w{3}/?????
The question mark is hard part that I could not figure it out.
Basically, I try to display the code with characters and numbers. I want to automatically add leading zeros on the number.
Byron
Seems that you're trying to match 5 digits at the end:
\w{3}/\w{3}/\d{5}

Categories