5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【C#】指数表記文字列からの数値変換【1.0E-6】

Last updated at Posted at 2022-04-20

結論

下記、ソースコードで変換可能です。

変換ソース
using System.Globalization;

var parseString = "1.0E-6";

//ここで変換しています。
decimal.TryParse(parseString, NumberStyles.AllowExponent | NumberStyles.Float, CultureInfo.InvariantCulture, out var output);

Console.Write(output);

おわりに

電圧計のコマンドレスポンスが指数表記で返ってくるタイプだったので調べました。こんなに簡単に変換できるのは凄いなと。思った次第です。CultureInfoを使っているのでWindowsの設定が日本ではない場合に不具合が出る可能性があるかも...。

参考

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?