Does anyone know how to calculate significant figures?

I am trying to write a routine that would return a varible set to the number of significant figures you ask for.

e.g.

call SigFig(1245.44, 3)
would return 1240

and SigFig(1245.44, 2)
would return 1200

e.t.c.

Any help is most appreciated