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.

Newcomers DBPro Corner / How to use the fractional part of a number.

Author
Message
New Comers Corner
18
Years of Service
User Offline
Joined: 24th Mar 2006
Location: Dallas Ft.Worth USA
Posted: 24th Mar 2006 12:48
Hello. I'm using the old version of Dark Basic, version 1 which I purchased on CD through the mail (on the black disc with white letters).
I've programmed many short things involving 3d successfully, learning from the example code included. The program works great.
Now for the first time I want to do something where I actually have to
write some math, and seem to have a problem. The program seems to turn every number in to an integer, I'm losing the fractional part of numbers! I need to work with the fractions, because I'm writing a biorhythm program.

For example, the total number of days lived has to be divided by
23 to find the number of physical cycles in a lifetime, and the fractional part after the decimal point is then multiplied to discover how far into the latest rythmic physical cycle the subject is. If the subject has been calculated to have lived 8783 days,
then my calculator shows that divided by 23 the number should be
381.86956 etc etc, a long fraction following. But when I do the math with Dark Basic, and print out the result to see what a simple division (using the /) produces, it seems to only produce the integer, before the decimal point, or 381.
Please don't tell me I need to purchase an upgrade to do simple math. The number of commands in version 1 are already far beyond my needs for simple fooling around. It just seems I'm doing something wrong because I can't seem to get the fraction. How do you use decimal numbers? I need the fractions.

Thanks

Student Programmer
Euphoria
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: United Kingdom
Posted: 24th Mar 2006 14:33 Edited at: 24th Mar 2006 14:35
"Error obtaining Source Code, invalid ID. Sorry but I've given up.
"

So I couldn't look at what you have written. So I'm gunna go throw caution to the wind and guess Assuming my version of DBP works in the same fashion, if you only use integers in your math, then you will only get integers back, irrespective of what you are doing with the result.


Example:



result = 381

Two ways to fix this:



result = 381.869nnnnn

or if your avoiding float vars like the plague you go a little messier



result = 381.869nnnnn


Hope thats what you meant, if not sorry (couldn't access the source).
driftman
19
Years of Service
User Offline
Joined: 7th Aug 2005
Location: Somewhere Outside of Sanity
Posted: 24th Mar 2006 15:22 Edited at: 24th Mar 2006 15:24
here's a little funtion that can return, to some accuracy, the fractional of a division.


I have a lil' white jacket that lets me hug myself forever.
chris319
18
Years of Service
User Offline
Joined: 30th Apr 2006
Location:
Posted: 30th Apr 2006 22:56
This works for me. All you have to do is add dot-zero to your integers:
chris319
18
Years of Service
User Offline
Joined: 30th Apr 2006
Location:
Posted: 30th Apr 2006 23:40
Let's try it this way.

This works for me. All you have to do is add dot-zero to your integers:

Login to post a reply

Server time is: 2024-09-24 19:33:14
Your offset time is: 2024-09-24 19:33:14