I have a suitecrm implementation where I would like to print a numbers in words in an invoice. The number is currency formatted, so it comes with commas (,). While I try to replace the commas with empty string, it doesn't work at all. In fact, in the below lines no characters is getting replaced at all.
//Value here is 10,720.00
$number = "\$" . $variableName . "_total_amount";
$newValueTemp = str_replace(",","",$number);
//Its still 10,720.00 after this
$newValueTemp = str_replace("0","",$number);
//Its still 10,720.00 after this. So basically nothing is getting replace.
Is this something to do with variable's variable?
You're using variable variables wrong:
$number = "\$" . $variableName . "_total_amount";
Will leave you with $number
being a string "$XYZ_total_amount"
. To make it a variable variable you should:
$number = $variableName."_total_amount";
and then use $$number
to get the value.
Do you have an idea of Currency module? If no, then read the following and hopefully something according to Suite/SugarCRM standards will give you better results:
Check bean file at path: modules/Currencies/Currency.php
Find function unformat_number
and study its code. It will give you an idea that how currency formatting works in SuiteCRM.
If you want to use "Currency" function in your code then the following code will be helpful for you:
<?php
require_once "modules/Currencies/Currency.php";
$unformated_number = format_number($number);