Jump to content

Need help on topic "number_format".


FutonGuy

Recommended Posts

Hi,

 

I am trying to extract numbers out from a field which is in alphanumeric. Did a search on the web and found that i can actually use "number_format" to extract the numbers out from the field. However i receive some notices and warning which read:

 

1) Notice: A non well formed numeric value encountered in C:\db\update.php  on line 50

 

2) Warning: number_format() expects parameter 1 to be double, string given in C:\db\date.php on line 50

 

my code is :

$HW_dev = $row_export['HW_dev_num'
$HW_dev_num = number_format($HW_dev,0,'','');

 

Can someone able to assist on this issue? thank you and your help is greatly appreciated.

 

Cheers

 

 

Link to comment
Share on other sites

Your PHP code snippet contains invalid syntax, I'm going to assume that does not occur in your actual code (since a different error would be issued).  Can you give an (or some) example of the values for $HW_dev as that would help us to diagnose why they cannot be formatted as a number.

Link to comment
Share on other sites

Ahh now that makes sense, you can't just ask PHP to magically figure out where the number is in there: you need to extract it yourself.  Depending on the format of the "number", various solutions might be more useful. For example you could simply get rid of all non-dijit characters in the string, or look for only the first sequence of digits, or extract a specific sub-string if they're always at the same position and length, or do something else entire if none of those are suitable to your specific needs.

Link to comment
Share on other sites

Will you be able to show me some examples how should i do it?

 

Only for the specific value that you've provided, anything other than that would be guesswork.

 

$value = 'BNM1234CO';
$number = strspn($value, '1234567890');
echo $number;

 

In this case the call to number_format is not needed because you were asking for the number to be formatted with no decimal places, no thousands separator and no decimal separator.... in other words, it will not make a difference.  Also note that the above is one of many (many!) ways to get a number from a string and could well turn out to be useless for your needs but that's all I/we can do with people who don't answer questions designed to help yourself.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.