-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?

10
  • 1
    var_dump($number) and see that it's not what you think it is... Commented Apr 4, 2018 at 8:24
  • Did you echo your $number and made sure that it really really is 10,720.00? Commented Apr 4, 2018 at 8: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. Commented Apr 4, 2018 at 8:26
  • actually what output do you need Commented Apr 4, 2018 at 8: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 Commented Apr 4, 2018 at 8:35

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Tried this. This comes out printing the variable name as "$aos_invoices_total_amount"
I think that were the problem is. This is inside suitecrm zend framework in a file called generatePdf.php. There its not working at all
That's pretty "basic" PHP, not sure how/if suitecrm could interfer with that. Sad to hear. Sorry, I'm of no further help then
Thank you anyway. Suitecrm community is also not of so much help.
Good luck though
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); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.