如何将浮动转换为货币 [英] How do I convert float to money

查看:99
本文介绍了如何将浮动转换为货币的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧所以我使用的是SQL Datareader,代码如下:

 ltUP.Text = dr [UnitPrice]。ToString(); 



现在我想要以这种格式显示UnitPrice:

 {0:#,###。00} ; 



,因为在我的数据库中它的浮动...当我在我的aspx文件中显示它时我想要它的钱...



我尝试了什么:



我试过这些:

 ltUP.Text = dr [UnitPrice]。ToString({0:#,###。00}); 



 ltUP.Text = dr [UnitPrice,{0:#,###。00}]。ToString(); 



但我知道错了..任何帮助都会很棒..

解决方案

尝试:

 tUP。 Text =((double)dr [UnitPrice])。ToString({0:#,###。00}); 


I假设您应该使用 GetDouble检索实际值 [ ^ ]方法(是的,SQL FLOAT 对应于C# double )方法,然后根据您的需要对其进行格式化。


尝试如下所示

 ltUP.Text =((double)dr [UnitPrice] )的ToString( #,### 00); 


okay so I am using SQL Datareader and the code is below..

ltUP.Text = dr["UnitPrice"].ToString();


Now I wanted the "UnitPrice" to be shown in this format:

{0:#,###.00};


because in my database its in float... I wanted for it to be in money when I display it in my aspx file..

What I have tried:

I've tried these:

ltUP.Text = dr["UnitPrice"].ToString("{0:#,###.00}");


ltUP.Text = dr["UnitPrice","{0:#,###.00}"].ToString();


But I know its wrong.. any help would be great..

解决方案

Try:

tUP.Text = ((double)dr["UnitPrice"]).ToString("{0:#,###.00}");


I suppose you should retrieve the actual value, using the GetDouble[^] method (yes, a SQL FLOAT correspinds to a C# double) method and then format it according to your needs.


try like this below

ltUP.Text = ((double)dr["UnitPrice"]).ToString("#,###.00");


这篇关于如何将浮动转换为货币的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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