PHP number: decimal point visible only decimal point [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
PHP number: decimal point visible only if needed
This Example using i want to 105.54 "-" Rremove
$foo = "-105.5457";
echo number_format((float)$foo, 2, '.', '');
want to 105.54

not clear enough...
echo number_format(abs((float)$foo), 2, '.', '');
?

Try use abs() "Returns the absolute value of number. " :)

Try this
$foo = "-105.5457";
echo number_format(str_replace('-','',$foo),2,'.','');

Related

How to format a string returned by a PHP function [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I wrote a program that uses an ISBN to query Amazon for that ISBN's price, and returns the following result:
5cb66919-8a8d-4c13-9175-790f0476508d0.0401580000000000TrueISBN9780340979266OffersAllAll0340979267809USD$8.09688USD$6.88598USD$5.98241010000
I need to format this so that I have the price information in a format that would be understandable to a human.
How can I do this?
Use this way..
<?php
$s = '5cb66919-8a8d-4c13-9175-790f0476508d0.0401580000000000TrueISBN9780340979266OffersAllAll0340979267809USD$8.09688USD$6.88598USD$5.982410100000';
$p = explode('USD',$s);
echo "<pre>";
print_r($p);
echo "</pre>";
?>
function returnPrice($response){
$prices = explode('USD',$response);
unset($prices[0]);
return $prices;
}

Create serial number with 8 length digits [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i want to create a format like this: 0000-0000. I already i have the unique number, but i need to merge it with my format type.
$my_id_unique = '60';
//some function....
//IT SHOULD OUTPUT LIKE THIS
$create_serial = '0000-0060';
$x = sprintf("%08d",$my_id_unique);
$create_serial = substr($x,0,4).'-'.substr($x,4);
With oneliner:
$create_serial = implode('-', str_split(sprintf('%08d', $my_id_unique), 4));
Or you could use str_pad:
echo str_pad('60', 9, '0000-0000', STR_PAD_LEFT);

Super easy php link construct [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
$out_terms[$term->name] = '' . $text . '';
Please help me check where the code gone wrong,any missing notes etc,as I am really 0 into php
$out_terms[$term->name] = sprintf('%s', $term_link, $text);
Try this (best construct) :
$out_terms[$term->name] = "$text";
or :
$out_terms[$term->name] = ''.$text.'';

Is it possible to combine array variable with array number to complete 1 variable? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
My code is as below :
assume that $a is a variable that 1 take out from DB and now i wan to combine it with an array number and produce an output that same with $box. Is it possible to do that ? or i m wrong ? please guide me.. thanks
$b="1-1-0-1";
$box=explode("-",$b);
$a="$box"; //from DB
echo $box[2];
echo "$a[1]";
Remove the quotes. Why are you so obsessed with them? https://stackoverflow.com/users/2892997/user2892997
$a=$box; //from DB
echo $box[2];
echo $a[1];
$b="1-1-0-1";
$box=explode("-",$b);
$a='$box'; //from DB
$a = substr($a, 1);
echo $box[2];
$c = $$a;
print_r($c);

PHP - Creating custom variable for template [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I don't know exactly how to say this, I'll use an example.
//[$var:Username|n] will print username with n length
$myText = 'The participants are [$var:Username|10], [$var:Username|8], and [$var:Username|6]';
$username = array('Alexandrite', 'Maximillian', 'Angelina');
$result = someFunction('[$var:Username|n]', $username, $myText);
echo $result;
//The participants are Alexandrit, Maximill, and Angeli
Any idea how to do this? Maybe using preg_replace?
I'm interested to know why you would even need to do this. Regardless:
preg_replace_callback('/\[\$var:Username\|(\d+)\]/', function ($match)
use (&$count, $username
) {
return substr($username[$count++], 0, $match[1]);
}, $myText);

Categories