Jump to content

[SOLVED] Selecting part of a variable


mrbill

Recommended Posts

Been trying to select part of a number (price) contained in a variable.

 

Here is a sample of the code I have been attempting to get to work for this

$amount = "$52.99";
$n = sscanf($amount, "%s %s", $dollars, $cents);
echo "<h2>" . $dollars . "</h2> <em>" .$cents. "</em>";

 

The above outputs everything to the $dollars and nothing to $cents. The dollar amount won't always be 2 digits so I would like to be able to just seperate from the right to the decimal, that is *.99* only and the dollar amount from the decimal to the dollar sign, *$52*.

 

All I am trying to do is take the $amount which is in this example $52.99 and separate the dollar from the cents so I can apply a style.

 

It should look something like this: $52.99

Link to comment
https://forums.phpfreaks.com/topic/56651-solved-selecting-part-of-a-variable/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.