Advertisement
zebadeee

Force one decimal place

Sep 20th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. n = effect("Slider Control")("Slider").value;
  2.  
  3.  
  4. // add one zeros, and make it an unsigned string -- we'll add the negative back later if it's supposed to be negative
  5. nScaled = Math.abs(Math.round(n * 10));
  6. s = "" +  nScaled.toString();
  7.  
  8. // pad low values with leading zeros to ensure at least 2 digits after we move the decimal point
  9. while (s.length < 2)  s = "0" + s;
  10.  
  11. // if it was negative, add the - sign back
  12. if (n<0) s = "-" + s;
  13.  
  14. // insert the decimal place before the last decimal place
  15. s = s.substr(0,s.length-1) + "." + s.substr(s.length-1,s.length)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement