Skip to content

Instantly share code, notes, and snippets.

@jimhigson
Last active January 19, 2024 11:27
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimhigson/7985923 to your computer and use it in GitHub Desktop.
Save jimhigson/7985923 to your computer and use it in GitHub Desktop.
round svg path to one decimal place
/* round("M -0.09375,-3 A 1.001098,1.001098 0 1 0 0,-1 C 0.56412939,-1 1,-0.56412939 1,0 1,0.27245181 0.8799664,0.4950336 0.6875,0.6875 A 1.016466,1.016466 0 1 0 2.125,2.125 C 2.6563912,1.5936088 3,0.83211769 3,0 3,-1.6450096 1.6450096,-3 0,-3 a 1.0001,1.0001 0 0 0 -0.09375,0 z")
=> "M -0.1,-3 A 1,1 0 1 0 0,-1 C 0.6,-1 1,-0.6 1,0 1,0.3 0.9,0.5 0.7,0.7 A 1,1 0 1 0 2.1,2.1 C 2.7,1.6 3,0.8 3,0 3,-1.6 1.6,-3 0,-3 a 1,1 0 0 0 -0.1,0 z"
*/
function round (path) {
return path.replace(/[\d\.-][\d\.e-]*/g, function(n){return Math.round(n*10)/10})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment