-3

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?

Jerokdeep
  • 121
  • 13
  • 1
    `var_dump($number)` and see that it's not what you think it is... – Niet the Dark Absol Apr 04 '18 at 08:24
  • Did you `echo` your `$number` and made sure that it really really is 10,720.00? – brombeer Apr 04 '18 at 08:25
  • We did. I have two other colleagues who are also bamboozled on this. When we print it, echo it.. and all the times it give 10,720.00. – Jerokdeep Apr 04 '18 at 08:26
  • actually what output do you need – parthi Apr 04 '18 at 08:28
  • It should come as 10720.00. I dont understand why people are so arrogant and downvoting this. I have this issue since last 2 days. After exhausting all my options I came here. seriously Frustrating – Jerokdeep Apr 04 '18 at 08:35
  • i think you want to get this output '$10720_total_amount' – parthi Apr 04 '18 at 08:41
  • Have you tried to str_replace $variableName before if goes into the $number line? – Joseph_J Apr 04 '18 at 08:44
  • @parthi - NO. I want the value changed from 10,720.00 to 10720.00. Variable "\$" . $variableName . "_total_amount" which translated to $aos_invoices_total_amount has this value 10,720.00 – Jerokdeep Apr 04 '18 at 10:20
  • Thanks to those GENIUSES who down-voted without solving this. – Jerokdeep Apr 04 '18 at 14:24
  • Simply, you want to unformat currency field value? Can you post complete code and detail that how it flows so that I can help you in a better way, I think this is not a difficult thing and I will help you to get a workable solution :) – Star Apr 11 '18 at 14:04

2 Answers2

0

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.

brombeer
  • 8,716
  • 5
  • 21
  • 27
0

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); 
Star
  • 3,222
  • 5
  • 32
  • 48