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 / code to demonstate a mathamatical problem - please help resolve it

Author
Message
PeterLewis
21
Years of Service
User Offline
Joined: 27th Sep 2003
Location: South Africa
Posted: 5th Nov 2003 00:56
This is a piece of badly written code that i threw together demonstrating a problem I have.

Please can someone give me a hand

Run the code to understand the problem


Thanks
Black Hydra
21
Years of Service
User Offline
Joined: 2nd Oct 2003
Location:
Posted: 5th Nov 2003 01:58 Edited at: 5th Nov 2003 01:59
I don't know whether this will help but when I was learning C++ we learned that decimals are actually somewhat deceptive and thus you cannot perform straight maths with them sometimes (I don't know whether this also applies to DB, this is an old DOS based C++).

For example 47 converted to decimals isn't actually 47.00000000 but rather 46.99999999999 and just rounded off. So if you said

deci# = 40.5 + 46.5
WHILE deci#/47 >< 1
ENDWHILE
Print "they are the same"

it would cause an infinite loop by those measures. I haven't tested that but in another case, perhaps yours, it might apply. I don't know whether that helps but you can't say I didn't try
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 5th Nov 2003 02:08
>< or is it <> ?

-RUST-
andrew11
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 5th Nov 2003 02:16
I think its something to do with how floats are stored in C++. Its not a DB problem.

You can work around it with something like this.

"All programmers are playwrites and all computers are lousy actors" -Anon
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 5th Nov 2003 06:23
I was curious if >< compiled?
Isn't not-equal-to supposed to be <> ?

-RUST-
PeterLewis
21
Years of Service
User Offline
Joined: 27th Sep 2003
Location: South Africa
Posted: 5th Nov 2003 09:14
I still want to retain the 2 decimal points

Your code workaround only gives me integer values

Maybe I should post this in DBDN to support

Thanks
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 5th Nov 2003 11:35
Unfortunately DBPro, as well as a lot of other languages, are not very good at storing and showing floats, thats why most languages have a formatted output function, like 9999999.99

IanM wrote a function that will generate a formatted string from a float value, look here:

http://developer.thegamecreators.com/?m=forum_view&t=18438&b=1

Boo!
PeterLewis
21
Years of Service
User Offline
Joined: 27th Sep 2003
Location: South Africa
Posted: 5th Nov 2003 11:50
I have written a function to solve my problem. Firstly a person cannot work in fractions when counting. I have checked on C++ and it specifically states that a float CANNOT be used for counting. I therefor have to go to the base on the currency which is cents. Everthing will work on cents and when I want to display the Rand value which is 100 cents per Rand I will use the following function

This function also adds in 0's where required to format the currency correctly

This function works up to a value with 9 digits thereafter ??????

Thanks for steering me in the right direction

Rgds
Peter

Login to post a reply

Server time is: 2024-11-25 16:35:15
Your offset time is: 2024-11-25 16:35:15