Android Question Converting Farenheit to Celcius formula

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Trying to do a conversion from Farenheit to Celcius.
I know if I pass in 32 I should get back 0
Problem is (value - 32.0) ends up being -32 instead of 0???

I know it must be something stupid... :)

B4X:
Public Sub temp_f2c(value As Float) As Float
    Return (value - 32.0) * 0.5555555
End Sub
 

derez

Expert
Licensed User
Longtime User
I've checked and it works fine like it should. You are doing something wrong elsewhere, like the argument that you supply...
I think it is better to write
B4X:
 Return(value - 32.0) *5/9
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
°C = (°F - 32) * 5/9

°F = °C * 1,8 + 32
 
Upvote 0

GuyBooth

Active Member
Licensed User
Longtime User
A formula that is easy to remember in both directions. It works because -40°F = -40°C :

°C = (°F + 40) *5/9 -40
°F = (°C + 40) *9/5 - 40

B4X:
' Untested
Sub Convert(Temp as Float, ReturnUnit as String)
Dim Multiplier as float
If ReturnUnit = "C" then Multiplier = 5/9 else Multiplier = 9/5
Return (Temp+40)*Multiplier - 40

:)
 
Last edited:
Upvote 0
Top