/    Sign up×
Community /Pin to ProfileBookmark

Excel Formula Converted to Javascript

I’ve got a fairly complicated formula in excel that I would like to convert over to javascript. Cell B5 is the only numeric input between the number 1-9. The below formula resides in cell C5, Here it is:

=(((B5*2.05)+(22*1)+(B5*1.65))/B5)*1.08

Is there any software out there that can do this?

Thanks for the help

to post a comment
JavaScript

16 Comments(s)

Copy linkTweet thisAlerts:
@lazyrmarkApr 25.2006 — Converts MS Excel spreadsheets (*.xls) into web-based calculators.

http://www.spreadsheetconverter.com/

You can email them an excel file to convert, they will email it back to you converted into web-based calculator page.

Haven't tried it out myself, may have to pretty soon. Appears way to easy to use, as opposed to doing it the hard way . . .

~mar
Copy linkTweet thisAlerts:
@HDCauthorApr 25.2006 — Thanks Mar, I just sent it off to them and I will let you know how it turns out.
Copy linkTweet thisAlerts:
@gphApr 25.2006 — There isn't anything to convert in the formula. It will work just as it is in JS.

var B5=8;

alert((((B5*2.05)+(22*1)+(B5*1.65))/B5)*1.08);
Copy linkTweet thisAlerts:
@lazyrmarkApr 26.2006 — I am not fluent in js, barely know enough to recognize it when I see it. But I have worked a little with spreadseets, since Daniel S. Bricklin almost single-handedly started the "pc revolution" by inventing VisiCalc.

The Excel Formula you quoted (below) is not completely closed. FUNTION/SUM begins with three left parantheticals, all three of which are closed. But the final factor "*1.08" is not closed. Here it is parsed:
=


(

(

(B5*2.05)

+(22*
1)

+(B5*1.65)

)/B5

)

*
1.08

You may find that the entire argument requires inclusion within the paranthenticals, like this:

=((((B5*2.05)+(22*1)+(B5*1.65))/B5)*1.08)

[count 'em. 6 opening parantheticals, 6 closing parantheticals, [I][B]including the final factor[/B][/I]]


I've got a fairly complicated formula in excel that I would like to convert over to javascript. Cell B5 is the only numeric input between the number 1-9. The below formula resides in cell C5, Here it is:

=(((B5*2.05)+(22*1)+(B5*1.65))/B5)*1.08

Is there any software out there that can do this?

Thanks for the help[/QUOTE]
Copy linkTweet thisAlerts:
@gphApr 26.2006 — The Excel Formula you quoted (below) is not completely closed. FUNTION/SUM begins with three left parantheticals, all three of which are closed. But the final factor "*1.08" is not closed.[/QUOTE]
It looks to me that the calculations on the left are evaluated then multiplied by 1.08. Enclosing the formula in parentheses won't affect the evaluation.
Copy linkTweet thisAlerts:
@lazyrmarkApr 26.2006 — Thanks for the reply.
It looks to me that the calculations on the left are evaluated then multiplied by 1.08. Enclosing the formula in parentheses won't affect the evaluation.[/QUOTE]
I noticed that when you first emended the initial argument, you did close the argument by adding an opening and closing parenthetical to his formule. Your correction ended with:
*1.08);[/QUOTE]

instead of

*1.08;[/QUOTE]

which is why it works.

His original EXCEL argument did not close with the paranthetical ")"



Even though it will still work in a spreadsheet without the extra opening and closing (), it will affect the way JS handles the math.



Is this right?



~mar
Copy linkTweet thisAlerts:
@gphApr 26.2006 — no, lots of parentheses make it confusing but I enclosed the formula in the alert() method, eg:

alert('Hello World');

or

alert(1*2);
Copy linkTweet thisAlerts:
@cadriangeorgeJun 23.2014 — hi everybody! i would like to convert this excel formula to javascript for adobe acrobat

=IF(CM2<600;0;(CM2-600)*0,16)

cm2 is named "SUMA3"

the result box is called "SUMA4"

the condition is that if "SUMA3" is lower than 600 then "SUMA4" its zero (0)

if "SUMA4" is higher than 600 then from that total is deduct 600 and the result is multiply with 0.16

thank you in advance
Copy linkTweet thisAlerts:
@zealoussJun 23.2014 — 
function checkVal (val) {

return (val < 600 ? 0 : ((val - 600) * 0.16));

}

// Call function with CM2 = 700

app.alert(checkVal(700));
[/QUOTE]


Hope this will help
Copy linkTweet thisAlerts:
@cadriangeorgeJun 23.2014 — thank you man
Copy linkTweet thisAlerts:
@cadriangeorgeJun 23.2014 — i don't want alert on the last function

i just want to ignore if is under 600 and to show 0
Copy linkTweet thisAlerts:
@chandanthaverJun 24.2014 — It is really tough for me also a log calculation i will pray for you some one give you a suitable answers. thank you for asking this question and i got also knowledge of your question. good luck.
Copy linkTweet thisAlerts:
@zealoussJun 24.2014 — i don't want alert on the last function

i just want to ignore if is under 600 and to show 0[/QUOTE]


Looking at your another post, I think you are doing this for adobe acrobat form. I am expert Adobe Acrobat javascript developer.

Now suppose you have 2 textbox in your pdf. One is "txt_CM" having value of CM2

and another is "txt_Result" in which you want to show the result of our formula;

So If you want to get the result in a text box named "txt_Result". The statement will be as follows (in the calcualte event of text)



function checkVal (val) {

return (val < 600) ? 0 : ((val - 600) * 0.16);

}

var cm = this.getField("txt_CM").value;

var cm_value = (isNaN(cm))? 0 : cm ;

event.value = (checkVal(cm_value) > 0) ? checkVal(cm_value) : "";

[/QUOTE]


I have modified the function also (there was a parenthesis problem). You can add function to document level javascript instead of calculate event.

If result is zero, textbox will be blank otherwise it will show result.

Hope this will help
Copy linkTweet thisAlerts:
@cadriangeorgeJun 24.2014 — please give an email adress or skype where to can easily connect for further discussion

thank you
Copy linkTweet thisAlerts:
@zealoussJun 24.2014 — Please check my profile. I have just updated it.
Copy linkTweet thisAlerts:
@cadriangeorgeJun 24.2014 — another issue i have:

IF the result between is negative how can i make it to show 0 ???

and to be considered zero for the next operation of the other formula from the next field??
×

Success!

Help @HDC 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 5.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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...