Welcome Guest, Not a member yet? Register   Sign In
number_format annoying error..
#1

[eluser]1mr3yn[/eluser]
Im always having this error and i cant figure it out.
Can someone give me the reason, why i this error came out? and the possible solution.

Code:
Severity: Warning
  Message: number_format() expects parameter 1 to be double, string given

Thanks!
#2

[eluser]theprodigy[/eluser]
can you give a context? How are you using the variable? It's possible that the variable you are passing in may contain an error of it's own (instead of the number you are expecting), and may be throwing the error since it is not a number
#3

[eluser]1mr3yn[/eluser]
I figure it out now, that error will came out if the variable has a null value.
I just inserted some condition like this:

Code:
if($row['contractPrice']){                                                
   print number_format($row['contractPrice'],2,".",",");
}
else{
   print "0.00";
}

Is their any other way, to solve this error of mine?
#4

[eluser]theprodigy[/eluser]
you may not just want to check
Code:
if($row['contractPrice'])

you may want to check
Code:
if(is_numeric($row['contractPrice']))

if($row['contractPrice']) will show as true if $row['contractPrice'] contains true, some number value, a string with length 1 or greater, an object, etc

Anything that doesn't evaluate to an empty or unset variable will return true in if($row['contractPrice']). The number_format() function requires a numeric value. I would check for that.
#5

[eluser]1mr3yn[/eluser]
thanks!
#6

[eluser]theprodigy[/eluser]
Glad I could help.
Let us know if there is any other way we can help.
#7

[eluser]skunkbad[/eluser]
You might also be able to do something like this:
Code:
print number_format((double)$row['contractPrice'],2,".",",");
#8

[eluser]Unknown[/eluser]
well on my project i was using previous version of php, and then when i shifted to new version of php that is php 5.3, i start getting this error message on Edizle.com.

for time being i put (double) with the first parameter of the function, but i know this is not a perfect solution. is there any other way so that i can prevent errors on the new version of php..???
#9

[eluser]Unknown[/eluser]
I have a similar challenge, please help me.
Quote:Warning: number_format() expects parameter 1 to be double, string given in /home/realest1/public_html/system/lib/I18N/IntFormatter.php on line 19
Here is line 19

Quote:return number_format($value, 0, ',', $this->thousands_separator);

Thanks
#10

[eluser]danmontgomery[/eluser]
[quote author="elgaxton" date="1309988058"]I have a similar challenge, please help me.
Quote:Warning: number_format() expects parameter 1 to be double, string given in /home/realest1/public_html/system/lib/I18N/IntFormatter.php on line 19
Here is line 19

Quote:return number_format($value, 0, ',', $this->thousands_separator);

Thanks[/quote]

How about checking either of the solutions posted in this very thread?




Theme © iAndrew 2016 - Forum software by © MyBB