C# Winform | Parse, Convert - System.FormatException
System.FormatException - 입력 문자열의 형식이 잘못되었습니다.
1. 원인
scientific notation - 과학적 표기법
Test Code
E- Parse, Convert Exception
string data = "1.7521E-06";
decimal data_Convert = Convert.ToDecimal(data);
decimal data_Parse = decimal.Parse(data);
|
cs |
RESULT
해결방법
https://docs.microsoft.com/ko-kr/dotnet/api/system.globalization.numberstyles?view=netcore-3.1
NumberStyles Enum (System.Globalization)
정수 및 부동 소수점 숫자 형식의 Parse 및 TryParse 메서드에 전달되는 숫자 문자열에서 사용할 수 있는 스타일을 결정합니다.Determines the styles permitted in numeric string arguments that are passed to the Parse and
docs.microsoft.com
Test Code
string data = "1.7521E-06";
decimal data_Parse = decimal.Parse(data, System.Globalization.NumberStyles.Float);
Console.WriteLine(data_Parse);
|
cs |
RESULT
'C# Winform' 카테고리의 다른 글
C# Winform | WebView / Tradingview - Chart (widget) (0) | 2020.10.16 |
---|---|
C# Winform | Pie Chart | Angle, Label (0) | 2020.09.02 |
C# Winform | Json - Read, Write (0) | 2020.08.24 |
C# Winform | List Sort | ObservableCollection Sort (0) | 2020.07.03 |
C# Winform | enum foreach (0) | 2020.05.06 |