Originally Posted by

**esamuel**
Hi, Sarah,

I implemented the code where it's belong, and it works.

There is some changes that you can help me make:

1) I need the default to be "cm"(I made changes in Unit control, but I need to change the JavaScript too, but the result was incorrect).

let say I create client with data in "in" and like to see measurement in "cm" and going back to "in , the data was incrementing each time I made this changes.

recordof .PNGrecordof1 .PNGrecordof2 .PNG
I need to fix this incrementation.

2) In the Calculation part You can see image , that when in "cm" the adding sum should be 10.2mm or 12.7mm , but it add 4" or 5" instead,( When the data is in "in" it's all correct.)

Ah.

What you need to do is convert the data coming in, which is in cm, to inches:

Code:

var cmInAnInch = 2.54;
underbust = Math.ceil(underbust/cmInAnInch);

Do all the calculations in inches, then at the end, convert it back to cm:

Code:

return newUnderbust * cmInAnInch;

In the case of the cup size calculation, you don't need to convert back to cm since you're returning a string. But for the new underbust, you would need to convert back if you're displaying it.

If you wanted to do all the math in cm, then you can't use the floor or ceiling functions for rounding. Nor can you use the modulo operator (%) based on your requirement that lengths are rounded to the nearest *inch*. The math operators would round your numbers to the nearest cm.

If you want the math that adds the 4" or 5" inches to work with the original cm data, you can store your inches calculations in separate variables and add the cm values to the original data that was given to the function. Also, I'm making the assumption that you meant 10.2*cm* and not 10.2*mm* (10.2mm would be 1.2cm and way smaller than 4"). If this assumption is false, then 10.2 and 12.7 need to be changed to 1.02 and 1.27 below:

Code:

function calcNewUnderbustAlt (underbust) {
var cmInAnInch = 2.54;
var **underbustIn** = Math.ceil(underbust/cmInAnInch);
var newUnderbust = 0;
// FYI: this does not round the cm value UP to the nearest inch before
// adding 10.2 or 12.7. It just adds 10.2 or 12.7.
if (**underbustIn** == 0) {
newUnderbust = 0;
} else if (**underbustIn** % 2 == 0) {
newUnderbust = underbust + **10.2**;
} else {
newUnderbust = underbust + **12.7**;
}
return newUnderbust;
}

I updated the component I posted earlier to do the conversion to inches before mathing if the data was cm values after recognizing that Math.ceil() on a cm value didn't round to the nearest *inch*.

## Bookmarks