Drkcore

04 07 2008 cpp Tweet

stringstreamでC++で小数部分と整数部分を分ける

modfを使うやり方。

double i,d;
d = modf(32.654, &i);
cout << "int: " << i << endl;
cout << "double: " << d << endl;

stringstreamを使ってint型の変数に流し込むと残りが小数部分になる。

double d;
int i;
stringstream ss;
ss << 32.654;
ss >> i >> d;

整数部分がパカッとはがれる感じ?

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021