Logic needed... decimal numbers

Status
Not open for further replies.

arian29

In the zone
I need some help with VB coding.
I need to split the decimal part of a number and use it later. eg.input is 10.88, splitted to say num1=10 and num2=88 .
Can someone help me with the logic here. :)
 

Pathik

Google Bot
suppose num=xx.yy
then
digit=0; // no of digits after decimal
num1=(int)num;
while(num!=(int)num)
digit++;
num2=num-num1*(10^digit);

//so num=num1.num2 now
 
OP
A

arian29

In the zone
Thanks Pathik
Code looks good for c/c++, however i am not sure how exactly i can implement it in VB ? any help here :)
 

redhat

Mad and Furious
try referring to this link, this is what u want:
*www.developerfusion.co.uk/show/5957/3/
 

victor_rambo

हॉर्न ओके प्लीज़
Hmmm. eveb I don't know VB. But I can think of some logic:
1. Convert the number into string.
2. Split the string using '.' as sperator
3. Convert the split parts into integers again and use them.
 

dheeraj_kumar

Legen-wait for it-dary!
Yeah theres a way...

get the floor function from *www.dreamincode.net/code/snippet178.htm

floor(10.88) = 10, it cuts down the number to the exponent(number before the dot) only.

To get the mantissa(number after the dot) subtract the floor value from the original number.

10.88 - floor(10.88) = 10.88 - 10 = 0.88

and multiply it by 100 to get 88, which is your num2.

so simply,

num1 = floor(10.88)
num2 = (10.88 - num1)* 100
 
OP
A

arian29

In the zone
Yeah theres a way...

get the floor function from *www.dreamincode.net/code/snippet178.htm

floor(10.88) = 10, it cuts down the number to the exponent(number before the dot) only.

To get the mantissa(number after the dot) subtract the floor value from the original number.

10.88 - floor(10.88) = 10.88 - 10 = 0.88

and multiply it by 100 to get 88, which is your num2.

so simply,

num1 = floor(10.88)
num2 = (10.88 - num1)* 100
Seems to be working... Thanks dheeraj_kumar
@adi... its vb6
 
Status
Not open for further replies.
Top Bottom