为什么的toString()引起我的字符串失去一个小数点? [英] why does toString() cause my string to lose a decimal place?

查看:193
本文介绍了为什么的toString()引起我的字符串失去一个小数点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是要前进,我的.NET和C#经验研究是非常有限的,一个人可以说我是一个完整的noob :)不过我确实有一些OOP的把握,因为我通常是在PHP(FWIW)工作。

Just to be forward, my .net and c# expierence is very limited, that one could say I'm a complete noob :) However I do have some grasp on OOP as I usually work in PHP (FWIW).

我的问题似乎与这一行:

My problem seems to be with this line:

Session["total"] = dt.Compute("SUM(price)", "").ToString();

将输出共说9.2里的价格是9.20,从几行记录这样:

which will output a total of say "9.2" where as the price is "9.20" from a few record lines as such:

dt.Rows.Add(strRecord, 9.20, dropDownListDistrict_stepTitle.Text);

9.20。因此9.20 + =18.40,但页面显示18.4。

Thus 9.20 + 9.20 = "18.40", but the page displays "18.4".

这显示的总和的标签是:

The label that displays the total sum is:

<asp:Label ID="labelTotal3" runat="server" Text="0" />

从我收集的,我是从某种类型转换问题的痛苦?

From what I've gathered, I'm suffering from some kind of type casting problem?

希望我没有错过任何东西,它有点难以显示所有code,但希望有人能指出我在正确的方向?

Hopefully I haven't missed anything, its a bit difficult to show all the code but hopefully someone can point me in the right direction?

问题;我怎样才能得到一个额外的小数位出现在我和(或它为什么放弃最后一个小数位?)。

Question is; how can I get an extra decimal place to show up on my sum (or why is it dropping the last decimal place?).

TIA
贾里德

TIA Jared

推荐答案

尝试的ToString(N2)

这篇关于为什么的toString()引起我的字符串失去一个小数点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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