# Calculating e, using matlab (how to get answer in double type)

#### seto6

1. The problem statement, all variables and given/known data

ok i am using Euler's way, i have to calculate "e"=2.718281828.

my script(see below) works but it only prints up to 4 decimal places, i have no idea why, help me please, thank you in advance.

2. Relevant equations

N/A

3. The attempt at a solution

Code:
function [eis] = euler1(in)
c=in-1;

while c>=1,

if c == double(in-1),
Q = double(c+(c/in));
end

Q= double(c + (c/Q));

alpha = double(Q);
c=c-1;
end
eis = 2+ 1/(double(alpha));

Last edited:

#### brushman

There's several ways to do this. The easy way is to just change the way strings are formatted.

>> help format

For more precision, try

>> help fprintf

### The Physics Forums Way

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving