var part = nlerp(+sourcePart, +targetPart, amount);
var sourcePoint = sourcePart.indexOf(".");
var targetPoint = targetPart.indexOf(".");
- var point = Math.max(
+ var point = Math.round(nlerp(
sourcePoint >= 0 ? (sourcePart.length - 1) - sourcePoint : 0,
- targetPoint >= 0 ? (targetPart.length - 1) - targetPoint : 0);
+ targetPoint >= 0 ? (targetPart.length - 1) - targetPoint : 0,
+ amount));
targetParts[i] = part.toFixed(point);
}
return targetParts.join("");
it("rounds integers", function () { with (this) {
assertEqual("12", lerp("0", "100", 0.123));
- assertEqual("12.3", lerp("0", "100.0", 0.123));
+ assertEqual("12.3", lerp("0.0", "100.0", 0.123));
assertEqual("12.3", lerp("0.0", "100", 0.123));
assertEqual("12.3", lerp("0.0", "100.0", 0.123));
}});
it("thinks about precision", function () { with (this) {
- assertEqual("12.30", lerp("0", "100.00", 0.123));
- assertEqual("12.30", lerp("0.00", "100", 0.123));
+ assertEqual("12.30", lerp("0.00", "100.00", 0.123));
assertEqual("12.300", lerp("0.000", "100.000", 0.123));
}});