簡體   English   中英

從字符串轉換為double,其數字大於std :: numeric_limit <double> :: digits10

[英]conversion from string to double with number greater than std::numeric_limit<double>::digits10

std::string str = "12345679012.124678";
double back = boost::lexical_cast<double>( str );
std::string str2 =boost::lexical_cast<std::string>( back );

//here str2 is equal to str

即使數字的有效位數大於std::numeric_limit<double>::digits10 (即15),這里是否正常(即最終字符串= orignal字符串)是否正常?

是的,這是正常的。

std::numeric_limit<double>::digits10指的是保證鑄造沒有損失的最大位數。

這並不意味着使用比限制更多的數字而損失,只意味着損失的可能性增加。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM