Public
Edited
Dec 13, 2023
Insert cell
Insert cell
(0.35).toFixed(1)
Insert cell
Insert cell
(0.35).toFixed(17)
Insert cell
Insert cell
(35 / 100).toFixed(1)
Insert cell
Insert cell
Math.round((35 * 10) / 100) / 10
Insert cell
Insert cell
roundFraction(35 * 10, 100) / 10
Insert cell
function roundFraction(numerator, denominator) {
// This only works if numerator >= 0 and denominator >= 1
//
// round(p/q)
// = floor(p/q + 1/2)
// = floor(2p/2q + q/2q)
// = floor((2p + q) / 2q)
// = (2p + q) // 2q (where // is integer division)
const n = BigInt(numerator);
const d = BigInt(denominator);
return Number((2n * n + d) / (2n * d)); // Note: 2n is the same as BigInt(2)
}
Insert cell
Insert cell
(0.4).toFixed(17)
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more