2016-01-21 26 views
1

要double轉換成字符串沒有科學記數法,建議的方式是ostringstream插件使用當前的語言環境嗎?

std::ostringstream strStream; 
strStream << std::fixed; 
strStream << value; 
std::string str = strStream.str(); 

Prevent scientific notation in ostream when using << with double & How do I convert a double into a string in C++?

我想雙轉換爲字符串,沒有任何隔膜和點/句號作爲小數點,即忽略語言環境。

ostringstreamstd::fixedshowpoint描述,我不能確定

  1. 小數點是否會在當前的區域?和
  2. str()返回的字符串中是否會有其他分隔符(例如,千分組)在基於locale的基礎上?

如果按照當前的語言環境,重寫的方式是什麼? - 它始終爲小數點/滿停止點,並且沒有分組?

回答

3

是的,流的默認語言環境是構建時的當前全局語言環境(請參閱您最喜歡的引用中的basic_ios::init的說明,然後檢查流的類型是否不這樣做 - 沒有標準類一樣)。

更改地區,使用basic_ios::imbue,因此你可能想的strStream定義後添加

strStream.imbue(std::locale::classic()); 

相關問題