473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Storing trailing zeros

Hey there,

I need to store the trailing zeros when I convert a numerical string into a double...I jsut don't know how.

I.E.

txtLimDist.text = 10.00 (user enters this in the GUI)

This gets converted to a double

limDist = Double

But if the user enters 10.00 (for example) it is converted to 10

I have to keep the .00 as the number is used to search an array and select the numbers less than or equal to the limDist...at the moment it selects any number starting with 10...so it gets 10.oo and 10.71....this stuffs up the rest of my calculations...can anyone help here?

Ta
May 24 '07 #1
4 1820
SammyB
807 Expert 512MB
What does your array look like? Is it Double or String? But in either case, 10.71 is greater than 10, so I'm confused. Your search must not be correct. Try single stepping thru the code (F10 for .Net, F8 for VB6 & VBA) and hovering over variables to see their values and make sure your code is correct.
May 24 '07 #2
HI,

My array is a double that stores numbers from a 2 column csv file (1st dimension is bearings, 2nd is distance). I get the user to enter a distance limit (limDist). I then sort the array by the 2nd dimension and then using the distance limit, I find the maximum and minimum values in the array 2nd dimension..... I have stepped through the code and it all runs fine but when I enter a distance limit of 10.00 the below code returns a maximum of 10.71 not 10.00 (in the csv file there are 2 values of 10.71 and one of 10.00 so I know that it should be returning 10.00 NOT 10.71) The same thing happens for similar values (eg. 14.00 returns 14.23, NOT 14.00)
Expand|Select|Wrap|Line Numbers
  1.  
  2. Call sortArrDist(arrSurvey) 'This definatley works correctly
  3. Try
  4. targetIndex = -1
  5. low = 0
  6. mid = 0
  7. high = arrSurvey.GetUpperBound(1) - 1 'max index
  8. target = limDist 'to search for
  9.  
  10. Do While ((targetIndex < 0) And (high >= low))
  11.    mid = (low + high) / 2
  12.    If (arrSurvey(mid, 1) = target) Then 'found it
  13.       targetIndex = mid
  14.    ElseIf (arrSurvey(mid, 1) > target) Then 'search bottom half
  15.       high = mid - 1
  16.    Else 'search top half
  17.       low = mid + 1
  18.    End If
  19. Loop
  20.  
  21. If low < arrSurvey.GetLowerBound(1) Then
  22.    minDist = Double.NaN
  23.    MessageBox.Show("The Distance Limit Entered does is not near a Survey point." _
  24. & vbCrLf & "The Closest Distance to this Limit is the Control Point")
  25. Else
  26.    minDist = arrSurvey(0, 1)
  27.    maxDist = arrSurvey(high, 1)
  28. End If
  29.  
I tried to format the limDIst in the Command Sub that calls the function that holds the above code (with 2 other claculations) but it returned max min and averages of 0.00 (I used Format(txtLimDIst.text, "0.00"); and also tried "f", "c",...but these are all formating for string output NOT conversion from string to doulbe and keepin the trailing zeros. I also tried using decimal, but I know that doesn't store trailing zero's...at least not for this purpose.....

I need to submit my work today! My tutor has made herself unavailable and I can't work this out!

Thanks

Kate
May 24 '07 #3
SammyB
807 Expert 512MB
Works for me, I think, but I had to change line 6 to
high = arrSurvey.GetUpperBound(0) - 1 'max index
May 25 '07 #4
Killer42
8,435 Expert 8TB
I agree with SammyB, the error must be in your search.

Sorry snooglets, but you're on totally the wrong track about the zeroes.

A numeric field, be in integer, double, or whatever, does not store any leading or trailing zeroes. It stores a numeric amount. If you want trailing zeroes, you can display it with as many as you want. If you need to know how many were there before you placed the value into the numeric field, then you'll have to store that information some other way. But I really doubt that you will need it.
May 25 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: BARBARA FLOYD | last post by:
Hi, I have an ASP file which is opened in MS Excel. I have used the "formatNumber" function to set the number of decimals for variables which are displayed. however Excel cuts off any zeros at...
5
by: Jason | last post by:
I have a column defined as DECIMAL(10,6). I want to display it as a string but I do not want the trailing zeros. I cannot seem to get CAST or CONVERT or STR to exclude the zeros. Examples:...
2
by: Keali | last post by:
for example: A1 = 123 A1=123000 <- final result A1 =1234 A1=123400<- final result A1=1 A1=100000<-final result
16
by: Alec S. | last post by:
Hi, I need a way of dividing up my site into "departments". What I want is to be able to allow some JavaScript functions to perform differently based on what department the current page is...
3
by: V. Jenks | last post by:
I need to store money values in C# and I noticed when using a float, the trailing zero was trimmed off automatically. I don't want this, is there a native type that will *not* do this so I can...
15
by: Bob | last post by:
I'm about to convert to string and use regex, but I thought there must be something I'm missing here that already exists. Bob
9
by: Chester | last post by:
I'm working on an app that records data collected by service technicians (VB.Net front-end, SQL Server 2000 back end). The technicians need to record numbers with varying scale and precision. For...
13
by: stephen b | last post by:
(apologies for cross posting from the moderated group..i'm sure you understand) Hello, I'm passing an array into a Constructor and hoping to use it as a pointer and store it as a class member...
1
omerbutt
by: omerbutt | last post by:
hi i am trying to store the longitude and latitude i have made the table with 3 columns codes, longitude , latitude and the type for longitude and latitude is decimal(15,11) but there are different...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.