# Thread: Excel Formula Converted to Javascript

#### Hybrid View

1. HDC
Registered User
Join Date
Jan 2006
Posts
301

## 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

2. Registered User
Join Date
Apr 2006
Posts
3

## Yep, converts XLS into HTML calculators

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

3. HDC
Registered User
Join Date
Jan 2006
Posts
301
Thanks Mar, I just sent it off to them and I will let you know how it turns out.

4. gph
Registered User
Join Date
Apr 2005
Posts
387
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);

5. Registered User
Join Date
Apr 2006
Posts
3
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, including the final factor]

Originally Posted by HDC
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

6. gph
Registered User
Join Date
Apr 2005
Posts
387
Originally Posted by lazyrmark
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.
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.

7. Registered User
Join Date
Apr 2006
Posts
3
Thanks for the reply.
Originally Posted by gph
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.
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);
instead of
*1.08;
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

8. gph
Registered User
Join Date
Apr 2005
Posts
387
no, lots of parentheses make it confusing but I enclosed the formula in the alert() method, eg:

alert('Hello World');

or

alert(1*2);

9. Registered User
Join Date
Jun 2014
Posts
6
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

10. Member
Join Date
Jan 2014
Posts
20
function checkVal (val) {
return (val < 600 ? 0 : ((val - 600) * 0.16));
}

// Call function with CM2 = 700
app.alert(checkVal(700));
Hope this will help

11. Registered User
Join Date
Jun 2014
Posts
6
i don't want alert on the last function
i just want to ignore if is under 600 and to show 0

12. Member
Join Date
Jun 2014
Location
Delhi
Posts
33
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.

13. Member
Join Date
Jan 2014
Posts
20
Originally Posted by cadriangeorge
i don't want alert on the last function
i just want to ignore if is under 600 and to show 0
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) : "";
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

14. Registered User
Join Date
Jun 2014
Posts
6
thank you man

15. Registered User
Join Date
Jun 2014
Posts
6
please give an email adress or skype where to can easily connect for further discussion
thank you

#### Thread Information

##### Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•