Just starting out? Need help? Post your questions and find answers here.
nblackburn
User
Posts: 67 Joined: Mon Aug 19, 2013 1:22 am
Location: United Kingdom
Contact:
Post
by nblackburn » Tue Sep 08, 2015 8:56 pm
In PureBasic i am trying to do some calculations to determine the height of something but for some reason the following returns zero, any thoughts?
Calculation:
PureBasic:
This is very strange to me and am not sure what is going wrong
Keya
Addict
Posts: 1890 Joined: Thu Jun 04, 2015 7:10 am
Post
by Keya » Tue Sep 08, 2015 8:58 pm
I think you just have to tell PB that its a floating point value, because if you encase the equation in StrF() it works. I had that problem too before I discovered StrF() and was just using Str() heehee
nblackburn
User
Posts: 67 Joined: Mon Aug 19, 2013 1:22 am
Location: United Kingdom
Contact:
Post
by nblackburn » Tue Sep 08, 2015 9:00 pm
Thanks, this was really off putting
Shardik
Addict
Posts: 2058 Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany
Post
by Shardik » Tue Sep 08, 2015 9:00 pm
Just try the following:
Code: Select all
Debug StrD((100 / 498) * 491, 8) ; Output: 98.59437751
Keya
Addict
Posts: 1890 Joined: Thu Jun 04, 2015 7:10 am
Post
by Keya » Tue Sep 08, 2015 9:02 pm
... yes or Doubles using StrD! ........ whichever one... Floats your boat
[edit] ok sorry that was terrible
GPI
PureBasic Expert
Posts: 1394 Joined: Fri Apr 25, 2003 6:41 pm
Post
by GPI » Tue Sep 08, 2015 9:29 pm
When you want to use float/double, you should add a ".0". Otherwise the compiler think you want to use integer.
Debug (100.0 / 498.0) * 491.0
Btw. When you want to use only Integer, better first * than /
debug (100*491)/498