how to restrict type "Double" variable to go upto 2 decimal places only?

hi,

i have declared two variables

dim a as double = 2.99

dim b as double = 2.999

and a result

dim result as double = a + b

when i check the output of the result variable.. will be  4.999 but i always want it to be as 4.99

how do i truncate the value to 2 decimal places

thanks,

regards


X
0
jibrankh
1/27/2006 3:36:43 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

2 Replies
633 Views

Similar Articles

[PageSpeed] 52

use string.Format.




The Killer Ninja Coding Monkeys thank those that mark helpful posts as answers.

My Site | My Examples | My Blog


0
RTernier
1/27/2006 4:20:27 PM

You can try Math.Round().. sample code is below..it will truncate the double upto 2 places

double a= 2.99;

double b= 2.999;

double c;

c = a+b;

double d = Math.Round(c,2);



My Blog


"Don't be afraid to be wrong; otherwise you'll never be right."
0
budugu
1/27/2006 4:40:09 PM
Reply:

Similar Artilces:

Is "Session" the best solution for transfering variables between "Web Forms"??
Hi all; I am using an ASP.NET Web Application (with VB.NET)... and this App used to manage customers' requests.. so, ther user will handel customer#1 data for a while, then he (the user) will handle the data of customer#2. and so on.. And I need to transfer some variables value from one page (Web Form) to onother pages (Web Forms), Is the "Session" variable the BEST solution? and do you recommend me to increase its live to 60 mins or more. (In case the user need approx. 1 hour to handle customer#1 data!!)?? Example of values I want to transfer: CustomerID, RequestNo, Co...

C#.Net "Double" and "double" When/Where to use?
Hi all     Please let me know the difference between "Double" and "double" in c#.Net (I understand that "Double" is structure      and "double" is an instance to that structure) differences if any thing else.     Also the context in which both has been used.(When/Where to use both). thanks all...      hi,my brains says Double is reference type & double is value type.regards,satishKind Attn: If a reply to your post helped you, kindly mark it as Answered.__________...

.NET 2 "FileUpload" control (or html "file"-type input)
I want to change the button on the control to be a specific colour i.e. other than the default grey. However, I can't find an attribute for this. The background attribute changes the input box area colour. Is there a way to change the colour of the button? Thanks http://www.quirksmode.org/dom/inputfile.html   NC...  ...

I've placed <forms loginUrl="home.aspx"></forms> in web.config and now all users that log in go to default.aspx
I've placed <forms loginUrl="home.aspx"></forms> in web.config and now all users that log in go to default.aspx.        <authentication mode="Forms">        <forms loginUrl="home.aspx"></forms>      </authentication>What attribute I should add, to make the user stay on the same page. Btw when I remove  <forms loginUrl="home.aspx"></forms>, users stay on the same page after login.Thanks. try one of these.....

double quote
hello there...  i tried everything of think but not working the way i wanted to be... not sure what i'm missing...i'm generating a <span> in code behind and then using in javascript.... here is what i'm doing code behind: int i=0string _keywordID = "keyword";string _name = row["visit_info_nm"].ToString().Trim(); String _getElementByID = String.Format("<span id='{0}' OnClick = \"document.getElementById('{1}').value='{2}';\">{3}</span><br>", i, _keywordID, _name, _name); here is what it generate : <span id='1' OnClick = \"document.getElementById('keyword')...

2 script tags, Script Language="javascript" and Script runat="server" in a web form.
Where should i place the javascript portion in the webform if i already had my <script runat="server"> (VB) place afterthat? Mark up: i understand that it should have 2 script tags used in the web form.  <SCRIPT LANGUAGE="JavaScript"> var isNN = (navigator.appName.indexOf("Netscape")!=-1); ...etc</script> <script runat="server">     Dim x, iRow, iCol, noRec As Integer   Dim i As Integer ... etc. <script> <asp:Content ID="First" ContentPlaceHolderID="aad"...

while saving the file "Save as Type" in SaveDialogBox shows "MicrosoftExcelSheet" and "AllFiles", how can i restrict "AllFiles" and show only "MicrosoftExcelSheet" ..
Below is code written for opening XLFile.  HttpContext.Current.Response.Clear();HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + astr_FileName); HttpContext.Current.Response.AddHeader("Content-Length", abyte_Data.Length.ToString()); HttpContext.Current.Response.ContentType = astr_ContentType; //octet-stream"; or //"application/vnd.ms-excel"; HttpContext.Current.Response.BinaryWrite(abyte_Data);    Udaya.M...

Before the AIM serach thing, I could go to the address box and type in the website's name with out "www" or ".com" and it would lead me straight to the website---for instants typing in "wiki" or "goog
Name: Aaron Mohammed Email: trinierrnboi117atyahoodotcom Product: Firefox Summary: Before the AIM serach thing, I could go to the address box and type in the website's name with out "www" or ".com" and it would lead me straight to the website---for instants typing in "wiki" or "google" or "myspace" now the stupid AIM search thing comes up and its REALLY annoying becuase im ust to the other way Comments: Thank You Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008052906 Firefox/3.0 From URL: ...

Before the AIM serach thing, I could go to the adress box and type in the website's name with out "www" or ".com" and it would lead me straight to the website---for instants typing in "wiki" or "googl
Name: Aaron Mohammed Email: trinierrnboi117atyahoodotcom Product: Firefox Summary: Before the AIM serach thing, I could go to the adress box and type in the website's name with out "www" or ".com" and it would lead me straight to the website---for instants typing in "wiki" or "google" or "myspace" now the stupid AIM search thing comes up and its REALLY annoying becuase im ust to the other way Comments: Thank You Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008052906 Firefox/3.0 From URL: h...

Error Number 23: cannot assign object of type "x" to variable of type "x"
I am running P/B 7.0.3 Build 10009 against an Oracle 8.0.5 database on Windows NT 4.0 Service Pack 4. I have a PFC application that ran just fine under 6.5.1 but is dying at runtime now with an Error Number 23 (which says you cannot assign an object of type 'x' to variable of type 'x'. There are 2 separate occurrences of this. One involves a window variable and the other involves a tab variable. Right now I am concentrating on the tab control. I have a userobject called tab_control which contains 2 tab pages (tabpg_list and tabpg_detail). In the tabpg_list objec...

"Go" to "History"
In the Firefox menu, "Go" brings up "History". So shouldn't it read "History", not "Go"? I'm by no means a Dev, but I can't imagine it would be difficult to change the word "Go" to "History". "Go" just doesn't make sense. It may as well say "Pancake". "History" is what it is, and "History" it should say. On Sun, 30 Apr 2006 10:40:22 -0700, unclespellbinder wrote: > In the Firefox menu, "Go" brings up "History". So shouldn't it read > &quo...

superreview granted: [Bug 116346] Content-Type should be supplied for form data of 'enctype="multipart/ form-data"'[form sub] #2
Johnny Stenback <jst@mozilla.org> has granted Boris Zbarsky <bzbarsky@mit.edu>'s request for superreview: Bug 116346: Content-Type should be supplied for form data of 'enctype="multipart/form-data"'[form sub] https://bugzilla.mozilla.org/show_bug.cgi?id=116346 Attachment 275968: Like so https://bugzilla.mozilla.org/attachment.cgi?id=275968&action=edit ------- Additional Comments from Johnny Stenback <jst@mozilla.org> Yeah, let's get this in and tested ASAP. r+sr=jst ...

superreview requested: [Bug 116346] Content-Type should be supplied for form data of 'enctype="multipart/ form-data"'[form sub] #2
Boris Zbarsky <bzbarsky@mit.edu> has asked Johnny Stenback <jst@mozilla.org> for superreview: Bug 116346: Content-Type should be supplied for form data of 'enctype="multipart/form-data"'[form sub] https://bugzilla.mozilla.org/show_bug.cgi?id=116346 Attachment 275968: Like so https://bugzilla.mozilla.org/attachment.cgi?id=275968&action=edit ...

Upgrading from "Visual Web Developer 2005 Express Edition Beta 2" to "Visual Studio 2005 Beta 2"
Newby question: I am learning ASP.NET and downloaded "Visual Web Developer 2005 Express Edition Beta 2" in order to practice and learn the ropes.I just received "Visual Studio 2005 Beta 2" and would like to upgrade. However, I haven't found any reference to removing "Visual Web Developer 2005 Express Edition Beta 2" before installing "Visual Studio 2005 Beta 2".Should I remove it?What do I need to back up before doing so?Thanks in advance,Ira I believe you can install VS on top of VWD. They, in fact, can coexits (although they will share some files).Thanks----------------------------------...

Web resources about - how to restrict type "Double" variable to go upto 2 decimal places only? - asp.net.web-forms

Resources last updated: 12/30/2015 2:36:42 PM