コンパイル時のオプションで -DVER=2019.09 の様な指定を使いたくなったので調べてみた.
コードは次のようなもの.
#include <iostream>
#include <iomanip>
#ifndef Test_Ver_F
#define Test_Ver_F 2019.0902
#endif
int main (int argc, char* argv[])
{
{
std::cout << Test_Ver_F << std::endl ;
std::cout << std::setprecision(20) << Test_Ver_F << std::endl ;
}
return 0 ;
}
pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $ g++ t_ccsw_d.cpp pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $ ./a.out 2019.09 2019.0902000000000953 pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $ g++ t_ccsw_d.cpp -DTest_Ver_F=2019.0902 pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $ ./a.out 2019.09 2019.0902000000000953 pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $ g++ t_ccsw_d.cpp -DTest_Ver_F="2019.0902" pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $ ./a.out 2019.09 2019.0902000000000953 pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $ g++ t_ccsw_d.cpp -DTest_Ver_F=\"2019.0902\" pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $ ./a.out 2019.0902 2019.0902 pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $ g++ t_ccsw_d.cpp -DTest_Ver_F=\"2019.09.02\" pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $ ./a.out 2019.09.02 2019.09.02 pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $

2019.0902 の様な浮動小数点の指定は特に変わった所はない.
但し浮動小数点による誤差などは考慮が必要.
文字列として扱いたいときは \” で括ればよい.