Attention: PROnetworks has upgraded our forum from phpbb2 to phpbb3!!

Please head over to our new converted forum at: http://www.pronetworks.org/forums/

This old forum will remain 'read-only' until approximately February 2009. We look forward to seeing you at the new forum!
Author Message
thankins
PostPosted: Thu Sep 25, 2003 12:04 am Reply with quote

PRO Level 2
 
 


Joined: 05 Mar 2003
Posts: 40
Location: USA
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
 
Back to top
Weaver
PostPosted: Fri Sep 26, 2003 11:41 pm Reply with quote

PROfessional Member
 
 


Joined: 18 Jun 2002
Posts: 2587
Location: /home/weaver/
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.

-Weaver
 
Back to top
UNIX2008
PostPosted: Thu Jan 15, 2004 2:07 am Reply with quote

PRO Level 11
 
 


Joined: 24 Dec 2003
Posts: 483
Location: Baltimore
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).
 
Back to top
Mac33
PostPosted: Thu Jan 15, 2004 6:52 am Reply with quote

PROfessional Member
 
 


Joined: 12 Mar 2002
Posts: 34345
Location: Scotland
Good point Chris smilenod
 
Back to top
dynamic_scripter
PostPosted: Sun Mar 07, 2004 2:55 pm Reply with quote

PRO Level 2
 
 


Joined: 03 Mar 2004
Posts: 12
Location: UK
easiest would probably be this ...
Code:

        Dim s As String = "9.0999990009999987"
        Dim x As Double = Convert.ToDouble(s.Substring(0, 4))

        MessageBox.Show(x) '/// this will return 9.09
 
Back to top
Smartcat99S
PostPosted: Tue Apr 27, 2004 9:03 pm Reply with quote

PRO New Member
 
 


Joined: 11 Jul 2003
Posts: 3
Location: Omaha, NE, USA
Code:
math.round(9.0999990009999987,2)
or
cdec(left("9.0999990009999987",4))


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
 
Back to top
BarnettRJ
PostPosted: Fri May 21, 2004 3:44 am Reply with quote

PRO New Member
 
 


Joined: 20 May 2004
Posts: 2
Location: South Africa
Code:
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:
CSng(Left(CStr(9.0999990009999987), 4))
, which is almost the same as Smartcat995's code, but begins with a numeric value.
 
Back to top
Back to top

Page 1 of 1

 


Tired of the Ads? Registered users have 80% less adverts.