big steppy
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

61 rinda
1.6 KiB

  1. function round(number,precision=3) {
  2. return Math.round(number*Math.pow(10,precision)) / Math.pow(10,precision);
  3. }
  4. function metricMass(kg) {
  5. if (kg < 1) {
  6. var mass = round(kg * 1000);
  7. return mass + (mass == 1 ? " gram" : " grams");
  8. } else if (kg < 5000) {
  9. var mass = round(kg);
  10. return mass + (mass == 1 ? " kilogram" : " kilograms");
  11. } else {
  12. var mass = round(kg / 1000);
  13. return mass + (mass == 1 ? " metric ton" : " metric tons");
  14. }
  15. }
  16. function customaryMass(kg) {
  17. var lbs = kg * 2.2;
  18. if (lbs < 1) {
  19. var mass = round(lbs * 16);
  20. return mass + (mass == 1 ? " ounce" : " ounces");
  21. } else if (lbs < 2000) {
  22. var mass = round(lbs);
  23. return mass + (mass == 1 ? " pound" : " pounds");
  24. } else {
  25. var mass = round(lbs / 2000);
  26. return mass + (mass == 1 ? "ton" : " tons");
  27. }
  28. }
  29. function metricLength(m) {
  30. if (m < 1) {
  31. var length = round(m * 100);
  32. return length + (length == 1 ? " centimeter" : " centimeters");
  33. } else if (m < 500) {
  34. var length = round(m);
  35. return length + (length == 1 ? " meter" : " meters");
  36. } else {
  37. var length = round(m / 1000);
  38. return length + (length == 1 ? " kilometer" : " kilometers");
  39. }
  40. }
  41. function customaryLength(m) {
  42. var ft = m * 3.28084;
  43. if (ft < 1) {
  44. var length = round(ft * 12,0);
  45. return length + (length == 1 ? " inch" : " inches");
  46. } else if (ft < 5280) {
  47. var end = customaryLength((ft - Math.floor(ft))/3.28084);
  48. var length = Math.floor(ft);
  49. return length + (length == 1 ? " foot" : " feet") + " " + end;
  50. } else {
  51. var length = round(ft/5280);
  52. return length + (length == 1 ? " mile" : " miles");
  53. }
  54. }