法语到英语的数字转换 [英] french to english numeric conversion

查看:129
本文介绍了法语到英语的数字转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我过去一周花了很长时间阅读Josuttis书中的语言环境

和Stroustrup。作为区域设置的简单测试,我在下面准备了以下

源代码。目的是将法国十进制数字

1.234,567转换为英语等价物1,234.567。

std :: locale oFrenchLocale(" French_Canada.1252");

std :: string oS =" 1.234,456" ;;

std :: istringstream oISS(oS);

std :: locale oOldLocale = oISS.imbue(oFrenchLocale);

double dValue;

oISS>> dValue;

oISS.imbue(oOldLocale);

std :: cout<< " \ n string =" << oS.c_str()<< \ n dValue =" << dValue;


输出为:

string = 1.234,456

dValue = 1


我期待dValue的值为1,234.567,但它只有
a值为1.会不会有人向我提供我正在犯的错误。

先谢谢。


Ian

I have just spent the past week reading up on locales in books by Josuttis
and Stroustrup. As a simple test of locales, I prepared the following
source code below. The purpose is to convert the French decimal number
1.234,567 to the English equivalent of 1,234.567.
std::locale oFrenchLocale( "French_Canada.1252" );
std::string oS = "1.234,456";
std::istringstream oISS( oS );
std::locale oOldLocale = oISS.imbue( oFrenchLocale );
double dValue;
oISS >> dValue;
oISS.imbue( oOldLocale );
std::cout << "\n string=" << oS.c_str() << "\n dValue=" << dValue;

The output is:
string=1.234,456
dValue=1

I was expecting dValue to have a value of 1,234.567 but instead it only has
a value of 1. Would someone kindly provide me with the mistake I am making.

Thanks in advance.

Ian

推荐答案

jd写道:
过去一周我一直在阅读Josuttis和Stroustrup撰写的书籍中的语言环境。作为区域设置的简单测试,我在下面准备了以下源代码。目的是将法语
十进制数1.234,567转换为英语等值1,234.567。

std :: locale oFrenchLocale(" French_Canada.1252");
std :: string oS =" 1.234,456";
std :: istringstream oISS(oS);
std :: locale oOldLocale = oISS.imbue(oFrenchLocale);
double dValue;
oISS>> dValue;
^^^^^^^^^^^^^^^^^让我们称之为第六行

oISS.imbue(oOldLocale);
std :: cout<< " \ n string =" << oS.c_str()<< \ n dValue =" << dValue;

输出结果为:
string = 1.234,456
dValue = 1

我期待dValue的值为1,234.567,而是它只有一个值1.有人会向我提出我正在犯的错误。
I have just spent the past week reading up on locales in books by
Josuttis and Stroustrup. As a simple test of locales, I prepared the
following source code below. The purpose is to convert the French
decimal number 1.234,567 to the English equivalent of 1,234.567.
std::locale oFrenchLocale( "French_Canada.1252" );
std::string oS = "1.234,456";
std::istringstream oISS( oS );
std::locale oOldLocale = oISS.imbue( oFrenchLocale );
double dValue;
oISS >> dValue; ^^^^^^^^^^^^^^^^^ Let''s call this "line six"
oISS.imbue( oOldLocale );
std::cout << "\n string=" << oS.c_str() << "\n dValue=" << dValue;

The output is:
string=1.234,456
dValue=1

I was expecting dValue to have a value of 1,234.567 but instead it
only has a value of 1. Would someone kindly provide me with the
mistake I am making.




我不是很精通locales,但我怀疑千元

分隔符不被接受作为数字的一部分(并被忽略)而

被视为字段分隔符所以第六行的输入仅仅是1和b。并停止。尝试从字符串中删除期间

使其成为


std :: string oS =" 1234,456";


..


V

-

请在回复时删除资金''A' -mail

我没有回复最热门的回复,请不要问



I am not very proficient in locales, but I suspect that the "thousands"
separator is not being accepted as part of the number (and ignored) and
instead is treated as a field separator so that the input on "line six"
only reads the "1" and stops. Try dropping the period from the string
making it

std::string oS = "1234,456";

..

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


2006年4月12日星期三19:58 :16 -0400Victor Bazarov

< v。******** @ comAcast.net>挥舞着魔杖,这条消息神奇地出现了:


On Wed, 12 Apr 2006 19:58:16 -0400 "Victor Bazarov"
<v.********@comAcast.net> waved a wand and this message magically
appeared:
std :: cout<< " \ n string =" << oS.c_str()<< \ n dValue =" << dValue;
std::cout << "\n string=" << oS.c_str() << "\n dValue=" << dValue;




哪一个更好,'<< oS<<''或''<< oS.c_str()''?


-
http://www.munted.org.uk


小睡一下,它可以拯救生命。



Which one''s better, ''<< oS <<'' or ''<< oS.c_str()''?

--
http://www.munted.org.uk

Take a nap, it saves lives.

Alex Buell写道:
Alex Buell wrote:
2006年4月12日星期三19:58:16 -0400" Victor Bazarov"
< v。******** @ comAcast.net>挥舞着魔杖,这条消息神奇地出现了:
On Wed, 12 Apr 2006 19:58:16 -0400 "Victor Bazarov"
<v.********@comAcast.net> waved a wand and this message magically
appeared:
std :: cout<< " \ n string =" << oS.c_str()<< \ n dValue =" << dValue;
std::cout << "\n string=" << oS.c_str() << "\n dValue=" << dValue;



哪一个更好,'<< oS<<''或''<< oS.c_str()''?



Which one''s better, ''<< oS <<'' or ''<< oS.c_str()''?




我不确定...... Lemme看到......<翻阅标准>

我找不到任何会使<<<< OS"有效...但是它在线编辑用b = b
...无论如何。懒得搞清楚。


我更喜欢隐含的转换。这就是为什么我可能会使用

后者。


V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要问



I am not sure... Lemme see... <leafing through the Standard>
I can''t find anything that would make "<< oS" valid... But it compiles
with online Comeau... Whatever. Too lazy to figure it out.

I prefer fewer implicit conversions. That''s why I''d probably use the
latter.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


这篇关于法语到英语的数字转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆