Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / How to remove the numbers after the (.)

Author
Message
3dZmaster
23
Years of Service
User Offline
Joined: 30th Jun 2003
Location: Finland
Posted: 15th Jul 2003 22:04
Let's say I have an variable wich contains data like 240.01241210201030203023. This kind of a huge number. How could I remove the numbers after the (.)? Or leave one number afterr it?
PLEASE ANSWER! Thanx.
Current project: Dodge Viper Car Game (Not named yet) Other car models are going to be included soon
3dZmaster
23
Years of Service
User Offline
Joined: 30th Jun 2003
Location: Finland
Posted: 15th Jul 2003 22:14
Ok. Now I know how to leave all the numbers after the (.). But How to leave one?

Current project: Dodge Viper Car Game (Not named yet) Other car models are going to be included soon
Flashing Blade
23
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 15th Jul 2003 22:27
To have just 1 decimal place I would do this:

eg no is 240.1241210201030203023 and assigned to variable a#

a#=240.1241210201030203023
a=a#
b=(a#-a)*10
b#=b
a#=a+(b#/10)
print a#
wait key
3dZmaster
23
Years of Service
User Offline
Joined: 30th Jun 2003
Location: Finland
Posted: 15th Jul 2003 22:40
thanx

Current project: Dodge Viper Car Game (Not named yet) Other car models are going to be included soon
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 15th Jul 2003 22:53
Or you can use the INT command...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins and other exciting things - oh my, yes!
3dZmaster
23
Years of Service
User Offline
Joined: 30th Jun 2003
Location: Finland
Posted: 15th Jul 2003 23:30
yeah but that doesn't leave any numbers after the (.)

Current project: Dodge Viper Car Game (Not named yet) Other car models are going to be included soon
Mentor
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 15th Jul 2003 23:37
far easier to do

a#=12.345
b#=(int(a#*10))/10

just multiply by ten or 100 or whatever then int and divide back to get the remainder, remember multiplying/dividing by ten moves the decimal point one place left or right, by 100 moves it 2 places, 1000 moves 3 places etc etc, cheers.

Mentor.

3dZmaster
23
Years of Service
User Offline
Joined: 30th Jun 2003
Location: Finland
Posted: 15th Jul 2003 23:52
thanx u

Current project: Dodge Viper Car Game (Not named yet) Other car models are going to be included soon
Codger
23
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 16th Jul 2003 00:03
Or you could create a funtion then you can use it anytime

a# = Roundit(240.1241210201030203023,1)

set cursor 10,10
Print a#
wait 3000

a# = Roundit(240.1241210201030203023,4)

set cursor 10,30
Print a#
wait 3000

Function Roundit(a#,b)

b# = int(a#*10^b)/ 10.0^b
Endfunction b#

Codger
23
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 16th Jul 2003 00:11
My function only works for 1,2& 3 places after that very strange results :-s
Anyone know why?

for i = 1 to 10
a# = Roundit(240.1241210201030203023,i)
set cursor 10,i*20
Print a#
next i
wait key


Function Roundit(a#,b)

b# = int(a#*10^b)/ 10.0^b
Endfunction b#

MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 16th Jul 2003 00:15
I've got a plug-in that does something like this that converts a string (up to a given number of dp) to a double.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins and other exciting things - oh my, yes!

Login to post a reply

Server time is: 2026-07-21 12:50:39
Your offset time is: 2026-07-21 12:50:39