I'm using the Units API module to convert psi and bar for a scuba diving application and getting some strange values returned from unitsapiconvert().

For example, if I convert 3000 psi to bar, this should be 206.8427184003111 (checked on several different conversion utilities found online). What unitsapi_convert() is returning is 20684. The right numbers are there, there just needs to be a shift in the decimal value. I'm no math whiz so I haven't a clue where to begin to track this one down and fix it correctly.

Comments

laboratory.mike’s picture

It sounds like you are getting kPa instead of bar, most likely it's a mis-entry of two values that likely would be next to each other in a table.

laboratory.mike’s picture

I checked the values; they have been entered correctly in the XML file, namely 1 bar = 100,000 Pa (1 E+5) and 1 psi ~ 6,894 Pa (6.894 E+3). I did notice that there are spaces in the decimals, i.e. for psi it's '6.894 757 E+03' . I would have to test and see if it's rendering as 6,894 or if it's rendering as something else. If so, there are several values that need to be changed.

laboratory.mike’s picture

What are the values shown on the help page? I am getting straight zeros (it's not reading the file), so maybe the read value is incorrect. If that's also right... hopefully we don't have to use drupal_set_message all over the place to find where it's going wrong.

r0nn1ef’s picture

Status: Active » Closed (works as designed)

After trying to find the problem for three days and eventually writing my own function for the conversions, i was still getting the same results. I then proceeded to inspect the source data; and XML file from my dive computer, and the pressure values are stored without the decimal value. I went back and verified the values in my dive log software from the manufacturer and compared that the the values stored in the XML. The solution was to multiply the source values by .01 to put the decimal in the correct position.