2

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?

2

3 Answers 3

11

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;

?>
Sign up to request clarification or add additional context in comments.

10 Comments

@urban Can you let me know how can I check with vi and what is vi?
The hidden character is before the 18, I see this in php fiddle.
can you please elaborate on this? in my code there is no space/char but it shows error
@SKIRT You need to copy past the script from this answer, it will be functional
Copy your codes into phpfiddle.org and its editor will show extra characters for both of your code snippets. What editor are you using?
|
0

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

?>

Comments

0

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.