Formatting a decimal to 2 decimal places

Hi - just testing some code, and the code below returns a number with 3 decimal places (eg. 450.000).

Will returning a decimal always give 3 decimal places, and if so, how can I remove the last one?
I don't want to use: Return String.Format("{0:C}", decRunningTotal) - as that will automatically add a $ or £ or whatever to the start, and I'd like to control that.
I'd really appreciate any help, thanks, Mark

Function GetItemTotal() As String
objDT = Session("Cart")
Dim intCounter As Integer
Dim decRunningTotal As Decimal
For intCounter = 0 To objDT.Rows.Count - 1
objDR = objDT.Rows(intCounter)
decRunningTotal += (objDR("RoomCost") * 1)
Next
If decRunningTotal > 0 Then
btnConfirmBooking.Visible = True
Else
btnConfirmBooking.Visible = False
End If
Return String.Format("{0:C}", decRunningTotal)
End Function
0
mtait
5/18/2004 9:13:24 PM
asp.net.getting-started 91979 articles. 3 followers. Follow

1 Replies
1064 Views

Similar Articles

[PageSpeed] 39


Return String.Format("{0:n}", decRunningTotal)

Regards

Andre Colbiornsen
---------------------------------
Seventh Day
Råbygatan 1A,
SE-223 61 Lund
Sweden
Mob.: +46-(0)708-97 78 79
Mail: info@seventhday.se
--------------------------------
0
adec
5/18/2004 9:27:27 PM
Reply:

Similar Artilces:

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...

string format 2 decimal places
how do you do string format conversion to 2 decimal places?e.g. convert 100 to 100.00convert 110 to 110.00convert 100.000 to 100.00 etc....Thanks! Well, here's one way you could do it:double value = double.Parse("100");string result = value.ToString("f2");This is using Numeric Format Strings (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconNumericFormatStrings.asp). There's also a class called NumberFormatInfo which gives you slightly more abstract ways to modify the string formatting. Both of these should work in other cultures, as well, so 1,000.00 will...

Formatting output
Hi, I'm recovering data from an SQL table using C#. I have an object that is DR["budget"] I can place this into a text box using: budget.Text = DR["budget"].ToString(); but it displays as 5000.0000 even though the column in the table is declared as 'Money' (how many currencies use 4 dec places?) How can I get it to display as just 5000.00 ? I've tried a variety of suggestions from the web, but none seem to get anywhere close. Regards, Bernard D   try this: budget.Text =(DR["budget"].ToString("c");  S...

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.&...

How to validate a decimal value with 2 digits after decimal point (de decimal point is a comma)
  I am a newbee, I have a Textbox where de user must write the price of an object. How can I validate de data entry in the Textbox (it must be a valid decimal with 2 digits after decimal point), and my pages are in  Portuguese so the decimal point to be accepted must be a comma   thanks  well you can do something like followig:  suppose TextBox1.Text = 123456,789 then you can say if(TextBox1.Text.Contains(",") ) {     int index1 = TextBox1.Text.IndexOf(",") +1;     int index2 = TextBox1.Text.IndexOf(...

plz Help: Converting 4 decimal places to 1 decimal place
Hi,I would like to convert 4decimal places to single(1) decimal place.For that i wrote below code. Its working sometimes. ex1:Input: StrAnlPct = "3.0000,2.9833,3.6546,4.65+6,5.54986,81.dsfds"Output: "3.0,2.9,3.6,4.6,5.5,81.d"For first example its working,Ex2:Input: StrAnlPct = "476290.4762,120.0000"For this i m getting error. Error is:    "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: startIndex "And    Source Error: At Line 590Line 588:            &...

Showing currency to 2 decimal places in gridview gets rounded off $ 57.50 as $ 58.00
Hi 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();Collectin...

decimal to varchar loosign decimal places
i convert 45.7895 using code below  CONVERT(varchar(10), TaxRate, 4) + '%' and the output is45.78%why the hell its cutting the 95 from the end? http://www.EasyStoreCreator.com/Everything your business needs to build an online store.------------------------------First Click DALhttp://asifashraf.com/FirstClickDal.asp------------------------------ASP.NET 3.5/sql server/svn hostinghttp://asifashraf.com/Aspnet3_5Hosting.asp Don't know for sure, but maybe it's because of the ,4.  Try ,10 as a test.C# <---> VB.Net Translator  Without knowing the datatyp...

2 decimal places
I am at the very basic stage - and I am pleased that I have been able to get my page to carry out a range of 5 calculations based on inputting 8 variables into 8 textbox web controls. My problem is that I would like the answers to be rounded to 2 decimal places (its a currency calculation) in the label web control. "Dim Calculation2 as Double " allows a multitude of decimal places "Dim Calculation2 as Integer " allows no decimal places My apologies for asking such a simple question but I cannot find the answer on the net anywhere. Thanks in anticipatio...

2 decimal places
Hello, The database has a currency field set to 2 decimal places and when I view the databse the entries look correct. But when I list the records in Aspx pages, the decimal place is truncated if they are zeros. Example: 65.00 appears as 65 5.20 appears as 5.2 Is there a way I can control this? Another problem is when I perform some operation like +.-.*,/, it also got the same problem. 65.10 * 1 = 65.1 will be shown in the browser. How do like set it to 65.10?I want the '0' to be remain there. Thanks. -Eugene- Hi Eugene, You can use the Format method and...

2 decimal places
Hi again yet another question   I am trying to divide two variables and * by a hundred to get a percentage. the two variables are doubles (Which I thought would give me my decimal) private wordCount as double = 0.0          private matchCount as double = 0.0 ------------------------------------  if matchCount > 0 then  dim anchor as string = "<a href=index3.aspx?QuestionID=" & Question_ID & "&Question=" & questionin & "&Answer=" & Answer & "&CategoryID=" & Category_ID & ">"...

Format decimal places
I have the following expressiona3 = GetNomBal(period, "40011") GetNomBal is a function which returns a "double" value, I want a3 to display at all times as with two decimal places, at the moment if the function returns 361.23 then a3 displays as 361.23 which is what I want, But if the value is say 200.00 then it displays 200 I tried a3 = Format(GetNomBal(period,"40011"),currency) but got an error. Can anyone help Thanks :)Ben Durkin MCP MCSA MCSE, Currently learning VB.NET and ASP.NET Burnley, England Try this, MyStr = Format(334.9, "###0.00");My ASP.NET blog ~God doesn't play dice....

Formatting decimal places...
I have an application which pulls data (a currency amt) from an Access db. The number is a subtotal from a purchase. This number has 2 decimal places which is correct for currency. The application then performs some functions to display the tax amount and then another function to display the total amount due. The tax and total due figures both have 3 decimal places, obviously a result of the mathematical functions being performed on them. I am presenting these numbers in the form of a label on my form. I know this is silly but how can I present the tax and total due figures with only 2...

Need to format float with no decimals or decimal point.
Is there a format for float that displays only the integer portion?  Or at the least, integer portion and decimal point but no digits to right? Eval("L_DistCalc", "{0:f}") Thank you, What about this: Eval("L_DistCalc", "{0:f0}")Limno Wow - thanks.  Is there a good reference book that has all the format forms, control structures and properties.  Everything I have has a the essentials but nothing in depth.  I know this kind of thing is simple but is sure is a lot to try and remember. Thank you,  You can sear...

Web resources about - Formatting a decimal to 2 decimal places - asp.net.getting-started

Wikipedia:Manual of Style/Text formatting - Wikipedia, the free encyclopedia
The most common use of boldface is to highlight the article title, and often synonyms, in the lead section (first paragraph). This is done for ...

Formatting « Above the Law: A Legal Web Site – News, Commentary, and Opinions on Law Firms, Lawyers ...
Above the Law: A Legal Web Site – News, Commentary, and Opinions on Law Firms, Lawyers, Law School, Law Suits, Judges and Courts

Android Studio 1.2 Reaches Beta, Adds Built-In Decompiler, Inline Debugger Variables, Smarter Formatting ...
When Android Studio v1.1 entered the Stable channel, about 6 weeks ago, the Dev Tools team gave word that v1.2 was already well underway and ...

TextExpander 2.0 Brings Rich Text Formatting, Fill-In Snippets And More
TextExpander has finally received its big 2.0 update.

WordEver HD - Text Editor with Redesigned Keyboard and MarkDown syntax & formatting highlight
Holen Sie sich „WordEver HD - Text Editor with Redesigned Keyboard and MarkDown syntax & formatting highlight“ im App Store. Sehen Sie sich Screenshots, ...

Macs are vulnerable to Thunderstrike 2 firmware malware that survives formatting
... Thursday, researchers will demonstrate that not only can Macs be remotely infected with malware, but that this malware can survive a user formatting ...

16 Tips on Blog Writing and Formatting
... again. My point is that you ought to take advice with a grain of salt. And that applies to this post as well. Writing blog posts and formatting ...

Select Text With Similar Formatting in Google Docs
Google Docs added a cool new feature that lets you select all the text with similar formatting, so you can quickly make some changes. It's like ...



Resources last updated: 12/21/2015 11:17:13 AM