施法提升::单位::数量翻倍 [英] Casting boost::units::quantity to double
问题描述
我需要将数量的值传递给图书馆进行评估. boost单位库在SI中采用双精度值,因此助推器单元库在确保这一要求方面非常吸引人.但是,如何将数量转换为双精度值?文档和示例似乎避免了这种情况,因为这样做的目的是正确地维护单元.
I need to pass the value of a quantity to a library for evaluation. The boost units library takes double values in SI, so the boost units library is very appealing in ensuring that requirement. However, how should I cast the quantity to a double value? The documentation and example seems to avoid this since the intent is to, rightfully so, maintain the units.
类似的东西:
quantity<pressure> p(101.1 * kilo * pascals);
double dblP = static_cast<double>(p); // double value in Pascals
仔细查看标题提示...是转换为基本类型的正确方法吗?
Going through the headers suggests... Is that the correct way to cast to the base type?
p.value();
推荐答案
The reference documentation shows that either implicit casts or the value()
member method can be used.
-
operator value_type() const;
允许隐式转换为value_type
implicit conversion to value_type is allowed
const value_type & value() const;
恒定访问值
这篇关于施法提升::单位::数量翻倍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!