Revu Specifics > Revu Forms
Converting a decimal number to feet and inches
(1/1)
EphPhoenix:
Hello!
Idk if anyone else has been hitting their head against a wall on this, but I managed to figure out the coding for it, so I thought I'd share. In the case of this, I have in the Calculate section of the Form Field Properties doing a simple math problem of subtracting one field from another. The coding for feet and inches conversion will go in the Format section in the Custom Format Script. The "event.value" described in the coding is the calculation from the Calculate section:
var realFeet = event.value
var feet = Math.floor(realFeet);
var inches = Math.round((realFeet - feet) *12) ;
var text = feet + "' " + inches + '" ';
if (event.value) event.value = text
Hope this helps someone! :3
ETA: Have an issue where if the inches = 12, it'll display it as, say 3' 12", as opposed to 4' 0". Working on a fix, and thought I had it by adding an if function, but now it just converts everything to 0 and rounds up. When I find it, I'll post it.
Fix found! Enjoy:
var realFeet = event.value
var feet = Math.floor(realFeet);
var inches = Math.round((realFeet - feet) *12) ;
if (inches < 12) {
var text = feet + "'-" + inches + '" ';
} else {
var text = (feet+1) + "'-" + 0 + '" ';
}
if (event.value) {
event.value = text;
}
Navigation
[0] Message Index
Go to full version