473,944 Members | 22,641 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Storing trailing zeros

2 New Member
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 1858
SammyB
807 Recognized Expert Contributor
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
snooglets7
2 New Member
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(txtLimDI st.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 Recognized Expert Contributor
Works for me, I think, but I had to change line 6 to
high = arrSurvey.GetUp perBound(0) - 1 'max index
May 25 '07 #4
Killer42
8,435 Recognized Expert Expert
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
3286
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 the end. e.g 4.650 displays as 4.65 the number of decimals I want to display to varies across the page, e.g. I cant say "display the whole with 3
5
15496
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: 45.340000 --> 45.34 27.700000 --> 27.7 55.000000 --> 55 Is there a function that will do this or do I need to write my own?
2
382
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
1558
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 assigned to. For example, if the user clicks on a link in a page, the link fires off a JS function that checks what department the page is in and does something. If the user clicks on that link on a different page assigned to a different...
3
11230
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 have my trailing zeros? I want $0.10 not $0.1.....obviously that gives me serious data issues. Thanks!
15
20121
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
8664
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 example, they may record one reading as 63.45 and the next as 123.1 and a third as 1.32456. That's fine - those can be saved as floating point numbers (very little math is done with these numbers so I'm not too worried about strange floating...
13
2163
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 for future use. So far, I'm just causing crashes, psuedo code below: double block; foo = MyClass(block);
1
5348
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 lengths for the longitude and latitude value means some where it has 5 digits after decimal and somewhere 8 and when i save it in the table it places zeros for the values which do not have the length of 15 what should i do if i do not want to store...
0
10148
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9974
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11548
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11140
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10679
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9871
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7402
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4519
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.