Posted By

charlesroper on 09/26/08


Tagged

snippet e-texteditor snippet-pipe


Versions (?)

Calculate % from pixels (snippet pipe)


 / Published in: Other
 

A snippet pipe that will calculate % based on a given pixel value and base unit.

E.g. If you want a 10px font-size expressed as a percentage, you would need to perform the following calculation (note 16px is the default base font size in all browsers):

10px / 16px = 0.625em * 100 = 62.5%

This snippet allows you to specify the desired pixel size and the base font size and will return the calculated % value.

  1. ${0:calculate ${1:10}px in % with a ${2:16}px base|
  2. ruby -e "n = (ENV['TM_TABSTOP_1'].to_f / ENV['TM_TABSTOP_2'].to_f)*100; n = n%1==0 ? n.to_i : n; print n.to_s + '%'"}

Report this snippet  

You need to login to post a comment.