5

I am writing a long document, which has a lot of money references in Indian rupees (easily typeset using package tfrupee).

Some definitions peculiar to Indian money before we proceed:

  1. Its grouped as ..,2,2,3. For instance, 100,000 is written as 1,00,000. (This is not particularly relevant to the question below, but the factoid is mentioned here for completeness).
  2. Currency unit lakh = hundred thousand (100,000)
  3. Currency unit crore = hundred hundred thousand (10000000).

Back to the question.

However, some of the audience of this document is going to be based in the US and Europe. So, I want to define the following (metacode).

\usepackage{tfrupee}
\usepackage{eurosym}

\newcommand{\scalefactor}[#1]{100000 if lakh and 10000000 if crore}

\newcommand{\rupeetodollars}{60.08} % Number of rupees to a dollar these days.
\newcommand{\rupeetoeuros}{82.32} % Number of rupees to a Euro these days.

\newcommand{\actualindianmoney}[2]{#1*\scalefactor{#2}}

\newcommand{\indianmoney}[2]{\rupee #1 #2\footnote{\$ \actualindianmoney{#1}{#2}/\rupeetodollars}. \eurosym \actualindianmoney{#1}{#2}/\rupeetosuros.}

with invocations like:

\indianmoney{10}{lakh} and \indianmoney{2}{crore}.

However, I have never done any floating point calculation (fp vs. pgfmath) using \LaTeX and how to convert lakh to 100000 and crore to 10000000 (to do the sensible multiplication above) as well as ensure only two decimal places in the result is throwing me.

Could someone help me out here?

PS: Is it possible to get compile time values for the exchange rates above instead of hardcoding numbers that may be obsolete in a few weeks (Though it has settled down of late, the Indian rupee has been one of the more volatile currencies around for the past two years).

user2751530
  • 1,102
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Heiko Oberdiek Apr 06 '14 at 19:36
  • For typesetting the number according to Indian rules, see http://tex.stackexchange.com/questions/144976/grouping-digits-according-to-the-indian-numbering-system-in-siunitx – egreg Apr 06 '14 at 19:41
  • Sorry, Heiko. Will be careful in the future. Nice seeing you here. I used to read your posts on comp.text.tex. – user2751530 Apr 07 '14 at 05:42
  • @user2751530 Once your question is usefully for you answered, you can upvote the answers and accept the one that siuts the best. – Tarass May 07 '14 at 15:23

1 Answers1

6

Please don't do any commercial transaction based on this code. And about getting compile time values, if you run with shell-escape enabled I guess you can run some external software which will pick up the info somewhere and then return it to TeX. But I don't know how one does these things, I am bad at getting money in my direction.

this answer does not pay attention to the actual formatting of the money amounts in Indian rupees, dollars or euros; for the latter two packages siunitx or numprint will help get the decimal marker and thousand separator of one's choice; for the former Grouping digits according to the Indian numbering system in siunitx achieves, also using xint, the grouping of digits according to Indian rules (but only for integer amounts).

rupee

\documentclass[a4papar]{article}
\usepackage[paperheight=5cm]{geometry}
% \usepackage[UKenglish]{babel}
% \usepackage[autolanguage]{numprint}
\usepackage{xintfrac}
\usepackage{tfrupee}
\usepackage{eurosym}

\newcommand{\rupeetodollars}{60.08} % Number of rupees to a dollar these days.
\newcommand{\rupeetoeuros}{82.32} % Number of rupees to a Euro these days.

\newcommand{\scalefactor}[1]{\csname scalefactor@#1\endcsname }
\makeatletter
\def\scalefactor@lakh  {100000}
\def\scalefactor@crore {10000000}
% 100000 if lakh and 10000000 if crore
\makeatother

\newcommand{\actualindianmoney}[2]{\xintMul{#1}{\scalefactor{#2}}}

\newcommand{\indianmoney}[2]{%
    \rupee #1 #2\footnote{\$ 
          \xintRound {2}{\xintDiv{\actualindianmoney{#1}{#2}}\rupeetodollars}}. 
    \EUR{\xintRound {2}{\xintDiv{\actualindianmoney{#1}{#2}}\rupeetoeuros}}}


\begin{document}\thispagestyle{empty}

\indianmoney {1}{lakh}

\indianmoney {0.123}{lakh}

\indianmoney {1}{crore}

\indianmoney {0.987}{crore}

\end{document}