A Digital Age Deserves A Digital Leader



Postby thankins » Thu Sep 25, 2003 4:04 am

Well I am back after a little time away from this board...and i have come back to ask another question.

Does anyone know how to convert a number such as 9.099999000999999 to just 9.09 in VB.NET. Any ideas? I am completely lost
PRO Level 2
Posts: 30
Joined: Wed Mar 05, 2003 5:35 pm
Location: USA

Postby Weaver » Sat Sep 27, 2003 3:41 am

You are going to want to look at topics with regard to "setting precision" You can set the precision to whatever you desire. Wish I could help you directly, but as you remember... I have never used VB.

Public Keys

The primary purpose of the DATA statement is to give names to constants; instead of referring to pi as 3.141592653589793 at every appearance, the variable PI can be given that value with a DATA statement and used instead of the longer form of the constant. This also simplifies modifying the program, should the value of pi change.
-- FORTRAN manual for Xerox Computers
PROfessional Member
User avatar
Posts: 1967
Joined: Wed Jun 19, 2002 12:05 am
Location: /home/weaver/

Postby UNIX2008 » Thu Jan 15, 2004 6:07 am

I would help you but I am more familiar with VB6.0, in my opinion VB.NET has completely changed from all previous versions. I think we are all in agreement when I say it was a sudden, stupid change on the part of the Micro-Machine (microsoft).
PRO Level 5
User avatar
Posts: 155
Joined: Wed Dec 24, 2003 6:00 pm
Location: Baltimore

Postby Mac33 » Thu Jan 15, 2004 10:52 am

Good point Chris :yesnod:
PROfessional Member
User avatar
Posts: 4910
Joined: Tue Mar 12, 2002 4:55 pm
Location: Scotland

Postby dynamic_scripter » Sun Mar 07, 2004 6:55 pm

easiest would probably be this ...
Code: Select all
        Dim s As String = "9.0999990009999987"
        Dim x As Double = Convert.ToDouble(s.Substring(0, 4))

        MessageBox.Show(x) '/// this will return 9.09
Image Image Image
PRO New Member
User avatar
Posts: 5
Joined: Wed Mar 03, 2004 10:59 pm
Location: UK

Postby Smartcat99S » Wed Apr 28, 2004 1:03 am

Code: Select all

It returns (9.10), the second(9.09) (I think, check the syntax, might have to flip the numbers.
If you need anything else, try msdn.com
PRO New Member
Posts: 2
Joined: Sat Jul 12, 2003 12:40 am
Location: Omaha, NE, USA

Postby BarnettRJ » Fri May 21, 2004 7:44 am

Code: Select all
Math.Round(9.0999990009999987, 2)
(which is presumably what you will want to use, because it takes a numeric value to begin with) will always round to the nearest place, so your question is (in terms of this code and in fact mathematically) incorrect. It is not possible to correctly return 9.09, when in fact the number is far closer to 9.1. If you wish to get 9.09, it is recommended that you do this...
Code: Select all
CSng(Left(CStr(9.0999990009999987), 4))
, which is almost the same as Smartcat995's code, but begins with a numeric value.
PRO New Member
User avatar
Posts: 1
Joined: Thu May 20, 2004 5:48 pm
Location: South Africa

Return to HTML, CSS, and Scripts

Who is online

Users browsing this forum: No registered users and 0 guests