0

hi,

i'm making a website for a company, with backoffice. when i want to add a new employee, i must specify the monthly fee and i created two inputs, one for the dollar part and the other for the cents parts. i wanted to concatenate the two parts with a dot in the middle and then cast to float. but when i insert the employee, the salary stays on 99.99

what can i do?

4
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by almostbob
0
$euros = $_POST['euros'];
$cents = $_POST['cents'];

$salary = $euros.".".$cents;
$salaryFloat = (float) $salary;
1
$euros = $_POST['euros'];
$cents = $_POST['cents'];
if(is_numeric($euros) && is_numeric($cents)) { $salary = $euros + ($cents / 100); }
else die('non-numeric inputs');

oneline code

isnumeric($_POST['euros']) && isnumeric($_POST['cents']) ? $salary=$_POST['euros']+($_POST['cents']/100):die('non-numeric inputs');

salaryfl;oat appears unneccessary

Edited by almostbob: n/a

1

is_int() better AB? is_numeric() will accept float (and hex?) as input.
Can just imagine some noob entering .89 for 89c as opposed to just 89

Votes + Comments
Thanks bloke
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.