hi all....

i want to add 01+1 and my desired output is 02.

my code is
var t=01;
var t2=t+1;

I want 02....what will i do?

Hi,

you can sumply use

``t2 = "0"+t2;``

but if you also want to give a condition that a 0 will be prefixed only for numbers less than 10.

then

``````if(t2<10)
{
t2 = "0"+t2;
}``````

Hi,

always mark thread as solved, when you get solution, as it will help others if they are searching for a solution.

## All 6 Replies

Hi,

you can sumply use

``t2 = "0"+t2;``

but if you also want to give a condition that a 0 will be prefixed only for numbers less than 10.

then

``````if(t2<10)
{
t2 = "0"+t2;
}``````

thank you Mr:Vicky.....thanks a lot..............

Hi,

always mark thread as solved, when you get solution, as it will help others if they are searching for a solution.

<script language="javascript">
var a,b,c;
a=prompt("enter 1st no");
b=prompt("enter 2nd no");
c=a*b
document.write(c);
</script>
</body>
</html>

0r
c=a-b
or
c=a\b
or
but a+b is not working...
do you know how to add two numbers?

pls 919895698898

hai are you know adding two numbers in javascript

for addition of two numbers in javascript, use the following

sum=parseInt(a)+parseInt(b);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.