Jump to content

Recommended Posts

toLocaleString is a javascript method available for most of the javascript types including the Number Type.

Are you trying to display the number using javascript or rendering it out via PHP?  Where/how are you getting the locale from?  Is this a fixed locale in your code, or something that can vary based on the user of the system?  

With PHP code you typically want to have installed the Intl extension, which then provides you various functions that support locale presentation.  Here's a quick example of the NumberFormatter class.

 

<?php

$fmt = new NumberFormatter('en_US', NumberFormatter::CURRENCY);
$fmt->setAttribute(NumberFormatter::FRACTION_DIGITS, 2);

$amt = 1234.56;

echo $fmt->formatCurrency($amt, 'USD') . PHP_EOL;
echo $fmt->formatCurrency($amt, 'EUR');

 

Don't understand what $amt = 1234.56; in this. I am in the UK. 

The line in the PHP here is 66. Thanks for your help.

<?php
// House contents Desmond O'Toole 2026-03-19
/*
Add 
*/
require ("../secure/SecurePDO.php");
session_start();
Session_Init();
$page = "Possesions Selection";
if(!isset($_SESSION["Pk"]))
{
  header('Location: index.php');
  exit;
}

$Pk = $_SESSION["Pk"];
if(KeyCheckX($Pk)== 0)
{
  header('Location: index.php');
  exit;
}
$pdo = connectDB();
$sqlContents = "SELECT * FROM `Contents` WHERE Cat = 0";
$stmt = $pdo->prepare($sqlContents);
$stmt->execute();

?>
<html>
<head>
<meta http-equiv="refresh" content="600 url=index.php">
<title>Possesions</title>
</head>

<body>
<h1><span style="color: #0000ff;">House contents</span></h1>
<table border="1" width="850px" cellpadding="1">
<tr>
<td width="200px"><b>Type</b></td>
<td width="220px"><b>Make</b></td>
<td width="150px"><b>Model</b></td>
<td width="180px"><b>Serial</b></td>
<td width="100px"><b>Cost</b></td>
</tr>

<?php
$totals = 0;
	while($row = $stmt->fetch())
{
$totals += (float)$row["Cost"];	
?>

<tr>
<td><?=$row["Type"]?>&nbsp;</b></td>
<td><?=$row["Make"]?>&nbsp;</td>
<td align="right"><?=$row["Model"]?>&nbsp;</td>
<td align="right"><?=$row["Serial"]?>&nbsp;</td>
<td align="right">£<?=$row["Cost"]?>&nbsp;</td>
</tr>

<?php }?>	

<tr>
<td><span style="color: #0000ff;"><b>Total</b></span></td>
<td></td><td></td><td></td>
<td align="right"><span style="color: #0000ff;"> 
<b>£<?php echo $totals?> /* THIS LINE is currently £10230.51
</b>
</span>
</td>
<tr>
	
</table>
</body>
</html>

 

 

That was just an example amount to demonstrate how the INTL Numberformatter class works.  You pass the number to be formatted, and the ISO 4217 Code and the currency string will be rendered for you.

In your case, the Pound Sterling ISO 4217 Code is 'GBP'.

 

So this line of code:

<b>£<?php echo $totals?> /* THIS LINE is currently £10230.51

 

Would be replaced with this:

<?php
$fmt = new NumberFormatter('en_GB', NumberFormatter::CURRENCY);
$fmt->setAttribute(NumberFormatter::FRACTION_DIGITS, 2);
?>
<b><?php echo $fmt->formatCurrency($totals, 'GBP'); ?></b>

You will see something like this:

£10,230.51

 

I will say once more that this requires the INTL extension installed.  Instructions for that are here:  https://www.php.net/manual/en/book.intl.php

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.