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
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.
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) -
-
Call sortArrDist(arrSurvey) 'This definatley works correctly
-
Try
-
targetIndex = -1
-
low = 0
-
mid = 0
-
high = arrSurvey.GetUpperBound(1) - 1 'max index
-
target = limDist 'to search for
-
-
Do While ((targetIndex < 0) And (high >= low))
-
mid = (low + high) / 2
-
If (arrSurvey(mid, 1) = target) Then 'found it
-
targetIndex = mid
-
ElseIf (arrSurvey(mid, 1) > target) Then 'search bottom half
-
high = mid - 1
-
Else 'search top half
-
low = mid + 1
-
End If
-
Loop
-
-
If low < arrSurvey.GetLowerBound(1) Then
-
minDist = Double.NaN
-
MessageBox.Show("The Distance Limit Entered does is not near a Survey point." _
-
& vbCrLf & "The Closest Distance to this Limit is the Control Point")
-
Else
-
minDist = arrSurvey(0, 1)
-
maxDist = arrSurvey(high, 1)
-
End If
-
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
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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?
|
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
|
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...
|
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!
| |
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
|
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...
|
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);
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |