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

## Homework Statement

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.

N/A

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

Related Engineering and Comp Sci Homework Help News on Phys.org
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