In JavaScript possiamo convertire pixel e millimetri con semplicità.
Il rapporto tra le due unità di misura è il seguente:
- 1 mm = 3.779528 px
- 1 px = 0.264583 mm
Quindi avremo (validazione puramente indicativa):
function toMM(value) {
// Usate anche typeof
var n = (value.indexOf('.') !== -1) ? parseFloat(value) : parseInt(value, 10);
return (n * 0.264583);
}
function toPX(value) {
// Usate anche typeof
var n = (value.indexOf('.') !== -1) ? parseFloat(value) : parseInt(value, 10);
return (n * 3.779528);
}