SK IRT
SK IRT

Reputation: 127

php float number error

I am trying to assign float value in php to variable I tried following,

$_web_lat=‎18.501059;
$_web_long=73.862686;

echo $_web_lat .'='. $_web_long;

[Parse error: syntax error, unexpected '.501059' (T_DNUMBER)]

OR

$_web_lat=floatval('‎18.501059');
$_web_long=floatval('‎‎73.862686');

echo $_web_lat .'='. $_web_long;

Both shows 0 as output? Anyone guide me on this?

Upvotes: 2

Views: 1202

Answers (3)

Karlo Kokkak
Karlo Kokkak

Reputation: 3714

Your code seems to have a hidden character ?

Try copy and use this:

<?php
$_web_lat=18.501059;
$_web_long=73.862686;

echo $_web_lat .'='. $_web_long;

?>

Upvotes: 11

ScaisEdge
ScaisEdge

Reputation: 133360

the sintax error is caused by automatic string conversion do the string operator . (dot concat) if you want avoid this you could use or cast float value ast string

  $_web_lat=‎18.501059;
  $_web_long=73.862686;

  echo (string) $_web_lat .'='. (string>$_web_long;

Upvotes: 0

Xay
Xay

Reputation: 248

Try to write floating values like

<?php

    $_web_lat=floatval('‎18.501059f');
    $_web_long=floatval('‎‎73.862686f');


$float_value_of_var1 = floatval($_web_lat);
$float_value_of_var2 = floatval($_web_long);

echo $float_value_of_var1; // 18.501059
echo $float_value_of_var2; // ‎‎73.862686

?>

Upvotes: 0

Related Questions