News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Floating Point Math Help!

Started by dexter, June 05, 2005, 09:39:12 AM

Previous topic - Next topic

dexter

Hello,

I've been checking out the demo version all day and would like to know if it's possible to use numbers to 4 decimal places e.g 1.2345

When I use the following;

Print 500+1.2345

I get 501.234 instead of 501.2345

Is there anyway to specify the number of decimal places used?

I hope somebody can help me with this' it's been puzzling me all day!

Thanks in advance

kevin

#1
Displayed floats are truncated, floats also are automatically rounded.    The user can't control this.   You can roll your own display though.

PlayBASIC Code: [Select]
Print 500+1.2345

print DecPlaces(500+1.2345)
;I get 501.234 instead of 501.2345




sync
waitkey

Psub DecPlaces(V#)
iv=V#
t=(v#-iv)*10000
s$=str$(iv)+"."+str$(t)
EndPsub s$







dexter

Brilliant!, Thanks alot Kevin for the quick response :D

I'll be purchasing PlayBasic as soon as I can find a free rs232 DLL to use with it.

Thanks again.

empty

Quoteas soon as I can find a free rs232 DLL to use with it.
You want to access the serial port?

dexter

QuoteYou want to access the serial port?

yes...sort of...

A USB GPS Unit that uses a virtual COM port driver

any ideas?

empty

It is possible to access the serial ports via the Windows API. If time allows, I'll write an example some time this week. You'd need to test it though as I don't think I have a device that requires the serial ports. :)

dexter

Thanks empty, that would be great!  

Can PlayBasic access the Windows API?
If you could point me in the right direction with regards to which command(s) to use I might be able to muddle through.

I think the content of the Help file for PlayBasic is extreemly good the only thing lacking is some sort of search function (or has it got one?)

Thanks again.

kevin

You can access API functions using the DLL commands.

There's not search for help ATM.   One day :)

empty

QuoteIf you could point me in the right direction with regards to which command(s) to use I might be able to muddle through.

The functions in question are all in the Kernel32.dll, if I remember correctly. You need
CreateFile
ConfigurePort
SetCommTimeouts
ReadFile
WriteFile
CloseFile

dexter

Thanks again, :D

time for a bit of googling