LoginSignup
1
2

More than 5 years have passed since last update.

C#でDecimalを文字列に変換する過程で桁数を処理したい。

Last updated at Posted at 2015-08-28

なんかあんまいいものがなかったので

var value = 123.123456789m;
var strValue = value.ToString("#.####"); 
// > 123.1234

-- 追記
以下のようにしても同じ結果が得られます。

var value = 123.123456789m;
var strValue = value.ToString("F4");
// > 123.1234

切り捨てられるので注意!

1
2
1

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
1
2