/    Sign up×
Community /Pin to ProfileBookmark

calculation Problem

I have the following calculation:

if (Cell[A,9] >0)
{
if(Cell[H,9] – (((Cell[B,9] * Cell[I,9]) + (Cell[C,9] * Cell[J,9])) / Cell[A,9])<= 0.02)
{
return true;
}
else
{
return false;
}
}

Cell[A,9] == 4000
Cell[H,9] == 1.02
Cell[B,9] == 3000
Cell[I,9] == 1
Cell[C,9] == 1000
Cell[J,9] == 1

Using the data above I think this calculation should return 0.02 as my answer. Have I my calculation built correctly?

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@scragarMar 21.2005 — [code=php]if (Cell[A,9] >0){
if(Cell[H,9] - (((Cell[B,9] * Cell[I,9]) + (Cell[C,9] * Cell[J,9])) / Cell[A,9]) <= 0.02){
return true;
}else{
return false;
}
}

//inserting numbers:
if (4000 >0){//true

// if(1.02 - (((3000 * 1) + (1000 * 1)) / 4000) <= 0.02){
// if(1.02 - ((3000 + 1000) / 4000) <= 0.02){
// if(1.02 - (4000 / 4000) <= 0.02){
// if(1.02 - 1 <= 0.02){
if(0.02 <= 0.02){//should return true.
return true;
}else{
return false;
}
}
[/code]

the problem is your use of numbers, try alerting out the numbers through several stages, your final number for the left hand side in the second if comes out as "0.020000000000000018" because the number does not work out very well in binary(you can only get very close, not precise)

something like this will work better:

[code=php]if (Cell[A,9] >0){
if(Math.floor(100 * (Cell[H,9] - (((Cell[B,9] * Cell[I,9]) + (Cell[C,9] * Cell[J,9])) / Cell[A,9]))) <= 2){
return true;
}else{
return false;
}
}[/code]
Copy linkTweet thisAlerts:
@clipperauthorMar 21.2005 — cheers for that works perfect
Copy linkTweet thisAlerts:
@clipperauthorMar 21.2005 — When I use the following data the calulation given does not work:

Cell[A,9] == 5

Cell[H,9] == 0.43

Cell[B,9] == 2000

Cell[I,9] == 1

Cell[C,9] == 3000

Cell[J,9] == 0

Is there any way to do this calculation so that it consistently works for different data?
Copy linkTweet thisAlerts:
@scragarMar 21.2005 — [code=php]if (Cell[A,9] >0){
if(Math.round(100 * (Cell[H,9] - (((Cell[B,9] * Cell[I,9]) + (Cell[C,9] * Cell[J,9])) / Cell[A,9]))) <= 2){
return true;
}else{
return false;
}
}[/code]


that should now work, but note that there are still some combos for which this won't work...

It would take a function about 200-300 times as big as your current if's to get it working for every value...
Copy linkTweet thisAlerts:
@clipperauthorMar 21.2005 — Thank You
×

Success!

Help @clipper spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...