0

How to display my price (200000 into 2 Lacs, 20000000 => 2 Crore)as decimal value in smarty

I stored price value as

200000
350000
2000000
20000000

in MySQL now i need to display this value as

2/2.00 Lacs 
3.5 lacs 
20/20.00 lacs
2/2.00 crore

Possible duplicate question is here

Thanks.

Community
  • 1
  • 1
iLaYa ツ
  • 3,941
  • 3
  • 32
  • 48

2 Answers2

2

I agree with Rob Agar.

I'm not sure on the figures you have, but something like this for a custom modifier is a starting point

function smarty_modifier_indian_currency($price)
{
    if($price>100000)
    {
        $lacs=$price/100000;
        // lacs

        if($lacs<100) return $lacs.' lacs';

        $crore=floor($lacs/100);
        $lacs=$lacs-($crore*100);

        if($lacs==0) return $crore.' crore';
        return $crore.'/'.$lacs.' crore';

    }
    return $price;
}
Waygood
  • 2,657
  • 2
  • 15
  • 16
1

The tricky bit is handling Indian currency formatting, which is covered in this question. After that it's straightforward to add a custom Smarty modifier to allow you to write something like this in your template:

{$amount|format_indian_currency}
Community
  • 1
  • 1
Rob Agar
  • 12,337
  • 5
  • 48
  • 63