EPPlus数字格式根据不同的文化 [英] EPPlus Number Format according to different Culture

查看:53
本文介绍了EPPlus数字格式根据不同的文化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此Excel屏幕快照链接以显示示例在特定单元格中,它由双重值,但在单元格中显示四舍五入的值.

This the Excel Screenshot link to show example In a particular cell, It consists double value but showing rounded value in the cell.

like如果在单元格中,该值为553236,但原始值为553236.456001

like If in the cell the value is 553236 but the original value is 553236.456001

,并且只有在单击该特定单元格时才能在顶部栏中看到该值.

and can only see this value on top bar when click on that particular cell.

但是我的问题是我已经将原始值转换为意大利货币,如何使其与上述相同

But my question is I have converted the original value into Italian currency, How to make it do the same as above

  • 在意大利文化中,553,236.456的值将转换为553.236,456
  • 仅需显示553.236,并且当单击顶部栏上的特殊单元格"时,该值应为553,236.456

为了将价值转化为意大利文化,我使用了以下代码

For converting the value into Italian culture I used the code as below

Convert.ToDouble(cellValue).ToString("C", CultureInfo.CreateSpecificCulture("it-IT")).Split(' ')[0]

用于拆分的不显示货币符号

used split to not show currency symbol

推荐答案

经过

cell.Value = Convert.ToDouble(cellValue,new CultureInfo("it-IT").NumberFormat);

cell.Value = Convert.ToDouble(cellValue).ToString("N",System.Globalization.CultureInfo.CreateSpecificCulture("it-IT")).Split(',')[0];

我了解根据文化的数字格式或数字取决于您系统的区域.如果数字被转换为不同的文化并且没有显示或显示错误的格式,则这是本地系统区域的原因.如果您将您的地区更改为该特定文化.您将得到完美的答案.我只是按照我的国家/地区格式在代码中使用了

I understood that number format or number according to culture is dependent on your system's region. If numbers are getting converted to different culture and were not showing or showing wrong format, that is cause of local system's region. If u change ur region to that particular culture. You'll get the perfect answer. I just did as per my country format in code like using

cell.Style.Numberformat.Format = "#,##0";

与此配合良好.在将代码提交到svn之后,当我尝试从主网站导出Excel时,根据系统所在的区域,它的运行情况很漂亮.如果我更改为意大利语,则Excel输出数字为意大利语格式,当我更改为Indian时,数字为印度数字格式.

it worked fine with this. After committing code to svn, when I tried the Export of Excel from main website it was working beautifully according to system's region. If I change to Italian, Excel output numbers were in italian format and when I change to Indian , the numbers were in Indian number format.

因此,不必担心您想要什么文化,请按照您的文化书写,一切都很好.在此之上,如果您仍然想根据特定的文化获取数字,请使用上述第二个代码,但是问题是您将获取以文本形式存储的数字.您无法添加或进行任何评估.

So Don't worry about whatever culture u want, do write according to ur culture all work's fine. Over this if u still want to get number according to particular culture use the above second code, but problem is u will get numbers stored as text. that u can't add or do any valuations.

这篇关于EPPlus数字格式根据不同的文化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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