Posts: 5,135
Threads: 241
Joined: Nov 2010
Reputation:
100
08-31-2011, 14:10
(This post was last modified: 08-31-2011, 14:12 by Pozzuh.)
for @ Tomsen1410
Code: //iprintln("2.4 will be: " + Number_func(2.4));
//2.4 will be: 4
Number_func(num)
{
num += " ";
num = StrTok(num,".");
return int(num[1]);
}
Posts: 1,830
Threads: 104
Joined: Jan 2011
Reputation:
46
(08-31-2011, 14:10)Pozzuh Wrote: for @Tomsen1410
Code: //iprintln("2.4 will be: " + Number_func(2.4));
//2.4 will be: 4
Number_func(num)
{
num += " ";
num = StrTok(num,".");
return num[1];
}
now it will return "4 "...
Posts: 5,135
Threads: 241
Joined: Nov 2010
Reputation:
100
(08-31-2011, 14:11)iAegle Wrote: (08-31-2011, 14:10)Pozzuh Wrote: for @Tomsen1410
Code: //iprintln("2.4 will be: " + Number_func(2.4));
//2.4 will be: 4
Number_func(num)
{
num += " ";
num = StrTok(num,".");
return int(num[1]);
}
now it will return "4 "...
What are you talking about?
Posts: 1,830
Threads: 104
Joined: Jan 2011
Reputation:
46
(08-31-2011, 14:13)Pozzuh Wrote: (08-31-2011, 14:11)iAegle Wrote: (08-31-2011, 14:10)Pozzuh Wrote: for @Tomsen1410
Code: //iprintln("2.4 will be: " + Number_func(2.4));
//2.4 will be: 4
Number_func(num)
{
num += " ";
num = StrTok(num,".");
return int(num[1]);
}
now it will return "4 "...
What are you talking about?
it will return the number + a space
Posts: 3,598
Threads: 265
Joined: Oct 2010
Reputation:
76
If there isn't a native function to do so, just do this (I never coded any gsc and I just guess this works).
C++ Code
foo = 1.2345; bar = foo - int(foo);
Posts: 18
Threads: 0
Joined: Jul 2011
Reputation:
0
(08-31-2011, 14:24)SuperNovaAO Wrote: If there isn't a native function to do so, just do this (I never coded any gsc and I just guess this works).
C++ Code
foo = 1.2345; bar = foo - int(foo);
I don't have a use for either one yet, but the difference is, @ Pozzuh 's version will return 4 and @ SuperNovaAO 's will return 0.4
Posts: 1,830
Threads: 104
Joined: Jan 2011
Reputation:
46
08-31-2011, 20:41
(This post was last modified: 08-31-2011, 20:41 by iAegle.)
(08-31-2011, 20:05)some_kid Wrote: (08-31-2011, 14:24)SuperNovaAO Wrote: If there isn't a native function to do so, just do this (I never coded any gsc and I just guess this works).
C++ Code
foo = 1.2345; bar = foo - int(foo);
I don't have a use for either one yet, but the difference is, @Pozzuh 's version will return 4 and @SuperNovaAO 's will return 0.4
C++ Code
foo = 1.2345; bar = foo - int(foo); num = int( bar * 100 );
?
Posts: 3,598
Threads: 265
Joined: Oct 2010
Reputation:
76
09-01-2011, 18:51
(This post was last modified: 09-01-2011, 18:52 by SuperNovaAO.)
C++ Code
while (int(bar) != bar) { bar = 10 * bar; }
To get 0 digits after the . after cutting the front of.
And yes, this is probably still faster than string manipulation since string manipulation the slowest thing possible is for computers (computers are made to calculate, not read).
|