Convert int64_t to double

前端 未结 4 1723
野趣味
野趣味 2021-02-07 05:31
  int64_t a = 1234;

  double d = (double) a;

Is this the recommended way?

4条回答
  •  情书的邮戳
    2021-02-07 05:50

    You can also use the conversion syntax, which is equivalent to a static_cast:

    int64_t a = 1234;
    double d = double(a);
    

    This is a useful syntactic construction in that it allows primitive and class types to be treated the same way in template code, either doing a static_cast, for the primitive, or invoking a constructor, for the class type.

提交回复
热议问题