add a decimal point

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2008
Posts: 13
Reputation: stephen lowry is an unknown quantity at this point 
Solved Threads: 0
stephen lowry stephen lowry is offline Offline
Newbie Poster

add a decimal point

 
0
  #1
Mar 23rd, 2009
hi guys i have designed software to read data from scales everything so far is so good except (yes theres always an except) part of my data arrives as 899 which is supposed to be 8.99 how can i converty this data to show 8.99 thankyou
stephen
Last edited by stephen lowry; Mar 23rd, 2009 at 5:27 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2002
Posts: 461
Reputation: waynespangler is on a distinguished road 
Solved Threads: 56
waynespangler waynespangler is offline Offline
Posting Pro in Training

Re: add a decimal point

 
0
  #2
Mar 23rd, 2009
If it is always .xx then divide by 100.
  1. Dim num As Decimal = 899
  2. Dim s As String = CStr(num)
  3. If s.IndexOf(".") < 0 Then
  4. TextBox1.Text = (num / 100D).ToString
  5. End If

As shown 8.99 would be put in the text box.
But if num = 899.1 then 899.1 would be put in the textbox.
Problem is 899.0 will be returned as 8.99 because the conversion to string removes the .0 so no dot is in the string.
Last edited by waynespangler; Mar 23rd, 2009 at 12:42 pm.
Wayne

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 13
Reputation: stephen lowry is an unknown quantity at this point 
Solved Threads: 0
stephen lowry stephen lowry is offline Offline
Newbie Poster

Re: add a decimal point

 
0
  #3
Mar 23rd, 2009
Originally Posted by waynespangler View Post
If it is always .xx then divide by 100.
  1. Dim num As Decimal = 899
  2. Dim s As String = CStr(num)
  3. If s.IndexOf(".") < 0 Then
  4. TextBox1.Text = (num / 100D).ToString
  5. End If

As shown 8.99 would be put in the text box.
But if num = 899.1 then 899.1 would be put in the textbox.
Problem is 899.0 will be returned as 8.99 because the conversion to string removes the .0 so no dot is in the string.

thanx wayne my main problem is that it may not always be 899 as it is scales the data is continuly changing (any ideas) thanx again
stephen
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 13
Reputation: stephen lowry is an unknown quantity at this point 
Solved Threads: 0
stephen lowry stephen lowry is offline Offline
Newbie Poster

Re: add a decimal point

 
0
  #4
Mar 23rd, 2009
thanx again i just noticed something in you code /100 and it worked fine something so simple i overlooked
cheers
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC