473,421 Members | 1,631 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,421 software developers and data experts.

extract int and fraction from string

I am trying to extract two parts of a number from an array element. Numbers
are in the format of 1.10, 2.50, 11.10, etc. Floor and ceiling won't work
right because close to 1.00, I get a zero, and I need the actual integer
part and the fraction part as an int, too.. TIA

here is the data

fields(0) = "Alena Sobran"

fields(1) = "4/4/1977"

fields(2) = "9.00"

code

datetimepicker1.Value = fields(1).ToString ' works

nupdHour.Value = fields(2).ToString ' seems to work

nupdMinute.Value = fields(2).Substring(fields(2).IndexOf(".", 2)).ToString '
wrong value

----
IOW, nupdHour should be 9 and nupdMinute should be 0 or 00

nupdMinute keeps returning 34

--

Patrick Sullivan, AA-BA, BA-IT
Nov 23 '05 #1
1 2063
Try placing fields(2) into a string variable before doing anythgin with it.
Do the same with the location fo the decimal point.

I see a few things in the code that could be problematic.

You are doing too many thigns in one step, and the code becomes difficult to
read and the mistakes hard to spot. Splitting this up into multiple lines
makes it easier to follow.

You are doing a substring on the database value before converting it to a
string. It has to be a string in order to use substring to begin with.
That said, I think the conversion will happen automatically, so this
shouldnt be the cause of your error, just a detail worth mentioning.

Your parenthesis is misplaced in the substring(indexof()) section of your
code. I think this is causing problems for you.

I'm not sure, as I always get confused with the index of substrings, but I
think you want to use indexof() +1 to start at the next character after the
decimal point.

Split up your functions as follows and check your values each step of the
way to confirm that each piece is workign exactly as expected. If you run
into a problem you can fixe one simple function instead of figuring which
part of a nested string function is failing.

dim strValue as string = fields(2).ToString
dim intDecPlace = strValue.Indexof(".")
nupdHour.Value = strValue
nupdMinute.Value = strValue.Substring(intDecPlace +1,2)

"Patrick Sullivan" <ps****@eatel.net> wrote in message
news:RJ********************@eatel.net...
I am trying to extract two parts of a number from an array element. Numbers are in the format of 1.10, 2.50, 11.10, etc. Floor and ceiling won't work
right because close to 1.00, I get a zero, and I need the actual integer
part and the fraction part as an int, too.. TIA

here is the data

fields(0) = "Alena Sobran"

fields(1) = "4/4/1977"

fields(2) = "9.00"

code

datetimepicker1.Value = fields(1).ToString ' works

nupdHour.Value = fields(2).ToString ' seems to work

nupdMinute.Value = fields(2).Substring(fields(2).IndexOf(".", 2)).ToString ' wrong value

----
IOW, nupdHour should be 9 and nupdMinute should be 0 or 00

nupdMinute keeps returning 34

--

Patrick Sullivan, AA-BA, BA-IT

Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: amarok | last post by:
Hello all. I'm a Software Engineering student, and I'm attempting to write a program in Java that does as follows: UML for the class: Fraction() Fraction(numerator: int) ...
6
evilmonkey
by: evilmonkey | last post by:
I am very new to programming as well as Java and this is my first post so please forgive me if this is not quite posted correctly. My Problem is that I have only been using scanner to get user input...
1
by: d0ugg | last post by:
Hi, I'm did a fraction program for one of my programming classes and it did compile, however when I'm running the program it crashes for some reason that I do not know. // fraction.cpp ...
2
by: d0ugg | last post by:
Hi, I'm doing a FRACTION program for one of my Programming classes and I'm getting some errors that I can't figure it out. Here is the Assignment: 1. Convert the fraction structure into a...
4
by: d0ugg | last post by:
Hello everyone, I'm creating a program that it is suppose to add, subtract, multiply and also divide fractions and after that, the result has to be reduced to the lowest terms. However, I'm not...
4
by: Semajthewise | last post by:
Hi All For those of you that helped me with the questions on this... Thank you! I believe I have solved all the bugs in the code and wanted to post the final product. This is a set of code to solve...
1
by: sony.m.2007 | last post by:
Hi, I have a decimal value and i need to take the digits after decimal places(fraction part only). Is there any simple functions available other than using string functions(searching for '.' and...
45
by: Dennis | last post by:
Hi, I have a text file that contents a list of email addresses like this: "foo@yahoo.com" "tom@hotmail.com" "jerry@gmail.com" "tommy@apple.com" I like to
10
by: Jason | last post by:
I'm making a program that will convert decimal inputs (in this case, in inches) and output a fractional answer. At the moment, I'm only able to output the fractional answer in three parts: A whole...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
1
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
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.