Jump to content

Help - Formating numbers


DesComm

Recommended Posts

Currently numbers are shown like 1234567 - How do you get formating to 1,234,567, I have tried to use php below results in a error.

// english notation (default)

$english_format_number = number_format($number);

// 1,235

I was able to format Money with commas using the following in

app.config.php now that formats $12,345.55

Config::Set('MONEY_FORMAT', '%i(#10n');

Link to comment
Share on other sites

To format a number, the first one was correct, but I believe you were getting an error because you haven't specified what the $number variable is.

Try this

<?php
$number = 123456789;
$format = number_format($number);
echo $format;
?>

If that still doesn't work, then try doing it straight from a number

<?php
$format = number_format("123456789");
echo $format;
?>

To format the money easily in phpVMS just use this:

<?php echo FinanceData::formatMoney(floatval(Auth::$userinfo->totalpay)); ?>

To get the pay for the currently logged in user, otherwise change Auth::$userinfo->totalpay to another variable depending on where you want to put it.

Link to comment
Share on other sites

To format a number, the first one was correct, but I believe you were getting an error because you haven't specified what the $number variable is.

Try this

<?php
$number = 123456789
$format = number_format($number);
echo $format;
?>

If that still doesn't work, then try doing it straight from a number

<?php
$format = number_format("123456789");
echo $format;
?>

Neither of the above fixed the issue, numbers still did not have commas in them. Any other fixes??

Link to comment
Share on other sites

Do you mind telling us where you want to put the code and what information you want to have formatted?

These were done in /core/app.config.php - we want this to apply to all numbers in phpvms. Weather it be logs, flights, hours all numbers should be shown with commas inserted.

Link to comment
Share on other sites

Hmmm, there is no setting to globally change all numbers to number_format() I don't think, so the best solution would be to change them manually.

I guess you could keep fiddling in the config file, but it's not set to change anything in particular so it might not work.

Link to comment
Share on other sites

  • Administrators

You could use the setlocale function and set the LC_NUMERIC category somewhere at the start of the script. -> http://php.net/manual/en/function.setlocale.php

No guarantees on this as there is a lot of places in phpVMS thst use various types of numeric values including flight numbers and pilot id's. You will probably end up with things like => Flight # ABC1,234 - most likely you will need to just use number_format where you want your specific format.

Link to comment
Share on other sites

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.

Loading...
×
×
  • Create New...