Showing currency to 2 decimal places in gridview gets rounded off $ 57.50 as $ 58.00

Big SmileHi

I am using a gridview .

the ui web page gets the data from my SQL database table the problem is the data in table has value of $ 57.50 but when the data is displayed it gets rounded off  to $ 58.00 and similarly several other data gets rounded off. How can I avoid this and display the actual amount $ 57.50 instead of rounding off??

 

here is the code how they are displayed in UI and now displaying as $ 58.00

// Amount_Paid fetching data from dbo.V_Payment_Amount_List

//DataFormatString="{0:c}"

ConnectionFinanceDB.DisconnectToDatabase();

CollectingDataSelected = ConnectionFinanceDB.CollectedFinaceData(
"SELECT DISTINCT Payment_Amount_Budgeted, Payment_Description FROM dbo.V_Payment_Amount_List " + SQLCONDITION);

DataTable Payment = new DataTable();

Payment.Load(CollectingDataSelected, LoadOption.Upsert);

 

foreach (DataRow DataCollectedRow in Payment.Rows)

{

if (DataCollectedRow["Payment_Description"].ToString() == "Enrollment(5 Days)")

{

EnrollAmtBTM.Text = DataCollectedRow[
"Payment_Amount_Budgeted"].ToString();EnrollAmtBTM.Text = String.Format("{0:c}", DataCollectedRow["Payment_Amount_Budgeted"]); // here is where the data is converred to currency

}

if (DataCollectedRow["Payment_Description"].ToString() == "Placement")

{

PlacAmtBTM.Text = DataCollectedRow["Payment_Amount_Budgeted"].ToString();

PlacAmtBTM.Text = String.Format("{0:c}", DataCollectedRow["Payment_Amount_Budgeted"]);

}

Thanks in advance

George

0
svgeorge
10/30/2007 4:50:29 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
909 Views

Similar Articles

[PageSpeed] 4

 Couple things. 

 

Numero Uno:

    When running in debug mode, after the EnrollAmtBTM.Text = String.Format line, hover your mouse over .Text to make sure your rounding isn't happening there.  

 

Once we remove the backend code, then it's probably in yoru presentation layer (your ASPX) in which case I'd have to see your display string.  By the way, just as a best practice...  dont format your stuff in teh code behind.  Fomrat it in the presentation layer.  Why?   Because it's the PRESENTATION layer.  You know, where you format stuff. :) 


If this post helped you, Mark As Answer.
0
jpuckett
10/30/2007 5:15:56 PM

Thanks that worked

I converted the amount datatype to money from earlier datatype smallmoney and then used the below code for currency and that worked.

foreach (DataRow DataCollectedRow in Payment.Rows)

{

if (DataCollectedRow["Payment_Description"].ToString() == "Enrollment(5 Days)")

{

EnrollAmtBTM.Text = DataCollectedRow[
"Payment_Amount_Budgeted"].ToString();EnrollAmtBTM.Text = String.Format("{0:c}", DataCollectedRow["Payment_Amount_Budgeted"]);

}

if (DataCollectedRow["Payment_Description"].ToString() == "Placement")

{

PlacAmtBTM.Text = DataCollectedRow["Payment_Amount_Budgeted"].ToString();

PlacAmtBTM.Text = String.Format("{0:c}", DataCollectedRow["Payment_Amount_Budgeted"]);

}

}

0
svgeorge
11/2/2007 3:18:07 PM

 :p  You marked your own post as the answer. 


If this post helped you, Mark As Answer.
0
jpuckett
11/2/2007 7:40:20 PM
Reply:

Similar Artilces:

Showing number to 2 decimal places in gridview
Hi, I am using a gridview control bound to an access database and one for the fields shows the price of an item. The prices in the database are stored in currency format. If an item is 35.00 it is displayed in the gridview as 35. It displays fine if the price was say 34.99. How can i ensure that the price is always displayed to 2 decimal places? I'm not sure if i have to alter my SQL query or whether it is a property of the gridview control. My simple SQL query is as follows:  SELECT tbl_products.prodCode, tbl_products.prodName, tbl_products.prodPrice FROM tbl_pro...

How to round to 2 decimal places
Hi, I have a variable declared as decimal I want to displat the result to 2 decimal places so I use Math.Round(Payment, 2) This works normally however if the value is say 200 or 200.1 it displays as that when really I want 200.00 or 200.10 How can I get around thisBen Durkin MCP MCSA MCSE, Currently learning VB.NET and ASP.NET Burnley, England Payment.ToString("n") should do it. Note that it is string formatting that does this.Thanks,Teemu KeiskiFinland, EU...

How to get 2 decimal places?
I have one session var and value of it will be double.How can i do it to be in 2 decimal places rounded up to nearest 5cents. eg.21.781 -> 21.10 21.322 -> 21.05 45 -> 45.00 Math.Round Method (Decimal, Int32, MidpointRounding)   Rounds a decimal value to a specified precision. A parameter specifies how to round the value if it is midway between two other numbers. Namespace: System Parameters d A decimal number to be rounded. decimals The number of significant decimal places (precision) in the return value. mode Specification for how to round d...

using javascript getting value from textbox when edit button is clicked and both controls are present in gridview control
Hi All using javascript I want to get value  from textbox when edit button is clicked and both controls that is texbox and button are present in gridview control .Alok Hi aloksinha83, Please see this post: http://forums.asp.net/t/1069245.aspx Thanks,Qin Dian TangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

Master Details in two seperate GridView Controls
I am simply trying to have a list of people in the top grid control (works fine), then when selected have the second Grid Control show details for that person(not working). Here is what I am trying from the load event: Sub BindData() Dim myConnection As New MySql.Data.MySqlClient.MySqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionSql")) Dim strPersonSQL, strActSQL As String strPersonSQL = "select row_id, first_name, last_name, middle_initial, dsi_id, created, created_by, program_of_study, email from tbl_person" Dim myPerCommand As New MySqlClient.MySqlComm...

Datagrid(.net 1.1) to GridView(.net 2.0) and using the RowUpdating event how to extract the values from the controls.
Ok  This is the settings: I use a Viewgrid with only itemtemplate colums for example. <asp:TemplateField HeaderText="Test"><ItemTemplate><asp:Label id="LBL_Test" text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' runat="server" meta:resourcekey="LBL_TestResource1"></asp:Label></font></ItemTemplate> <EditItemTemplate><asp:TextBox ID="HDN_Test" Text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' Runat="server" meta:resourcekey="HDN_TestResource1" /></EditItemTemplate></asp:TemplateField>  The ...

Round up function to 2 decimal places
Hi there, I'm facing problem with using round up function. Eg. round (633.675,2) = 633.68 if I use round function when perfrom multiplication, eg. total = 4.2245 * 150 total = 633.675 round(total,2) = 633.67, it should be 633.68 I wonder is it the powerbuilder bug. Currently I'm using PB6.5 build 4444 Please help. thanks! Please email me at lee.sheuefen@eonbank.com.my or lsheue@yahoo.com Regards, Sheue Fen Are you sure the result is not already rounded (e.g. real value = 633.674666) because you're using a datawindow c...

formating to 2 decimal places in a GridView
sounds simple but I just cannot get anything to work I have tried many variations of these String.Format("{0:f2}",DataBinder.Eval(Container.DataItem, "A")) DataBinder.Eval(Container.DataItem, "A", "{0:F2}")  tried it in a bound column which does not work either but I want to use a textbox any help please  jnc Hello, Take a look at the following article to see if this solves your problem :) Alot of formating information :)http://msconline.maconstate.edu/tutorials/ASPNET2/ASPNET07/aspnet07-01.aspx  Hope this helps.&...

Getting the control id of a control inside gridview control
 uhmm.. a little bit confusing regarding my subject because i dont know how to say it...by the way my problem is how can i get the id of a control (e.g. textbox) inside the gridview... and the textbox is in the templatefield... is there any way i can get its id??  hoping i could get a reply as soon as possible... Regards,MhaeyPlease remember to click “Mark as Answer” on the post that helps you.. =) What do you want's to do by getting the id of the Text box? Do you want's to find particular Textbox with certain id ? Kamran ShahidSr. Software Engineer(MCP,MCAD.net,MC...

Trying to load user control Dynamcially but getting error " Control 'ctl02_GridView1' of type 'GridView' must be placed inside a form tag with runat=server"
I am tired of this error and now writing a post.  My Web application has two pages. Page one has drop down list which redirect the page to another page . where I am going to load the usercontrol dynamically according to the choice of the user.     protected void ddlViewReport_SelectedIndexChanged(object sender, EventArgs e)  { if (ddlViewReport.SelectedIndex == 1) { Session["ReportType"] = ddlViewReport.SelectedIndex; Response.Redirect("RepReportingPage.aspx"); int crosspagevalue = ddlViewReport.SelectedIndex; } if (ddlViewReport.SelectedIndex == 2) {...

Rounding a number to maximum 2 decimal places.
In a grid datawindow I want to round a number (a double) to maximum 2 decimal places. So 78 must be shown as 78 79.1 as 79.1 58.25 as 58.25 12.136 as 12.14 The column is no input. Which format do I have to specify ? I've tried #.00 but then the number is always shown with 2 decimal places so 79.1 is shown as 79.10 I've also tried #.## but then the 78 is shown as 78. (notice the decimal point after the number). I suppose the last phenomenon is a bug ? Is there a solution for this common problem ? I'm using PowerBuilder 6.5 build 444. Luc Vermincksel TeSSA...

How do I round and truncate a float to 2 decimal places?
I have a float of 70.83333333343 If I do this SET @Output=ROUND(@Output, 2, 1) -- @Output is DECLARED as FLOAT I get this: 70.82999999999999 I want: 70.83 How do I do that? Thanks in advance... i think if you set @output as decimal(10,2) it will have only 2 digits after decimal..i'd normally limit it in the db itself so i dont have to worry abt conversion everytime. hth***********************Dinakar NethiLife is short. Enjoy it.*********************** Thanks. This is a calculated value, so I can't do anything to the database about this. But t...

Rounding Money to 2 Decimal Places In Grid View
Im using various grid views within my aps.net pages that show the values of SQL money fields, problem is there showing 4 decimal places instead of 2. How do i get it to just display 2 ? Help fixing this would be much appreciated.  you can add a format {0:F2} to your binding expression. like this for a BoundField:<asp:BoundField DataField="Price" DataFormatString="{0:F2}" HtmlEncode="false" />  And like this for a templated column<asp:TemplateField> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("Price", "{0...

Why Gridview control do not show the $ sign for the values declared as currency
Why Gridview control do not show the $ sign for the values declared as currency.  Gridview control do fetches the value of column type from schema column DATA_TYPE. Do not forget to mark it as answer!!Our economy is bad due to corruption and monoply! Some people may not want the currency symbol. You can add it with the DataFomatString:   <asp:BoundField DataField="Price" DataFormatString="{0:C}" HeaderText="Price" SortExpression="Price" />  Steve Wellens My blog In my application I do not kno...

Web resources about - Showing currency to 2 decimal places in gridview gets rounded off $ 57.50 as $ 58.00 - asp.net.presentation-controls

Currency - Wikipedia, the free encyclopedia
A much more general use of the word currency is anything that is used in any circumstances, as a medium of exchange. In this use, "currency" ...

Currency - Wikipedia, the free encyclopedia
A currency (from Middle English : curraunt , "in circulation", from Latin : currens, -entis ) in the most specific use of the word refers to ...

OzForex aims for 24hr currency trades - HeraldSun Search Search
... a 24-hour service for people wanting to exchange global currencies in an attempt to beef up its customer numbers around the world. THE currency ...

OzForex aims for 24hr currency trades
OZFOREX will transform into a 24-hour service for people wanting to exchange global currencies in an attempt to beef up its customer numbers ...

China's currency gets backing from head of IMF
The head of the International Monetary Fund says she supports adding China to an exclusive club of the world's top currencies.

China's yuan poised to join exclusive IMF currency club
The yuan is set to join the IMF's exclusive club of reserve currencies, with the fund's staff supporting its inclusion after months of persuasion ...

Bitwalking dollars: Digital currency pays people to walk
A new digital crypto-currency has been launched that is generated by human movement.

EU Rules Bitcoin is a Currency, US Says Bitcoin is a Commodity; Which Side is Correct? What About Gold ...
European Court of Justice Rules Bitcoin is a Currency Last week, the European Court of Justice ruled Bitcoin is a Currency and Exchanges are ...

Cisco Forecasts Miss Estimates as Currency Erodes Growth
Cisco Systems Inc. said weaker global economic growth and the strength of the U.S. dollar are hurting international sales of its equipment that ...

Bitcoin to be major reserve currency by 2030?
Bitcoin industry insiders have issued an optimistic prediction for the cryptocurrency over the next few decades.

Resources last updated: 11/24/2015 10:32:02 AM