I can’t make a sum

Asked

Viewed 18 times

-1

Hello, I am developing an application that makes a calculation of electricity consumption in React Native.

In it, I have 2 pickers: one of hours and the other of minutes. And to make it easier on the account I’m converting the minutes into hours, but at the time of adding up the hours and minutes it just puts one next to the other!

Example: The user has selected that his device is on for 5:30 a day. I convert the 30 minutes into hours: 30 / 60 = 0.5, and together with the 5 hours: 5.5 hours

But the application returns me the value one beside the other and not summed as in the image: inserir a descrição da imagem aqui

So is the assembly of my function:

function handleSubmit() {
const convertedHour = hour + (min / 60);
alert(convertedHour)

}

const [hour, setHour] = useState('00');
const [min, setMin] = useState('00');
  • 1

    Set an initial state with number and not string. If necessary, do type conversion.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.