Skip to content

Instantly share code, notes, and snippets.

@matt-dale
matt-dale / toFixedReplacementTest.js
Created January 31, 2021 16:35
toFixed(2) replacement. Gets around floating point division to produce a value from 0 to 1 for use as a percentage in a progress bar
const totalLength = []
totalLength.length = 10000
totalLength.fill(1)
const values = []
totalLength.forEach((x, idx) => values.push(idx))
const toFixedReplacement = (val1, val2) => String(Math.min(val1/val2, 1)).substring(0,4)
const toFixed = (val1, val2) => Math.min(val1/val2,1).toFixed(2)
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script type="text/javascript" src="draw2d/lib/shifty.js"></script>
<script type="text/javascript" src="draw2d/lib/raphael.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"