Ask Your Question
0

Convert numbers to English words [closed]

asked 2012-03-14 20:07:38 +0100

anonymous user

Anonymous

I do a lot of spreadsheets requiring me to write some figures in words and in numbers. I wish I would have a function in LibreOffice that would convert numbers to english words function. For example, convert the number 587 to "Five Hundred and Eighty Seven".

I know Microsoft Excel has this function somewhere, (see http://support.microsoft.com/kb/213360) but I tried copying that code to LibreOffice and it didn't work. Since I know absolutely nothing about code... I can't do anything!

Help?!?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2015-10-23 02:02:47.061728

2 Answers

Sort by » oldest newest most voted
2

answered 2012-03-14 23:11:14 +0100

m.a.riosv gravatar image

updated 2013-01-22 10:06:51 +0100

qubit gravatar image
edit flag offensive delete link more

Comments

No longer works with Libreoffice 4.0 and above.

grn gravatar imagegrn ( 2013-08-01 15:21:26 +0100 )edit

Hi @gM, http://extensions.libreoffice.org/extension-center/numbertext-1 claims that it is compatible with LO4.0. If it is not working with LO4.0 for you, please try to contact the extension author. For more information, see this page: https://wiki.documentfoundation.org/QA/BugReport/Extensions

qubit gravatar imagequbit ( 2013-08-01 16:41:00 +0100 )edit

@grn, it works as expected for me. Details here.

oweng gravatar imageoweng ( 2014-04-16 08:39:37 +0100 )edit
0

answered 2013-02-22 13:45:33 +0100

updated 2013-02-22 20:00:11 +0100

qubit gravatar image
REM  *****  BASIC  *****
Option Explicit

Sub Main
  Print getAmountInWords("999999999.99")
End Sub


'********************************************************************************************************
'Function Name      :   getAmountInWords
'Description        :   To convert the Amount value into words(formatted as "000000000.00")
'                       (Maximum allowed limit 999999999.99)
'Input Parameters   :   Amount
'Returns            :   String
'Creat by           :   Sanjeev Meher on 9th Feb 2013
'Specific Logic used:   None
'********************************************************************************************************
Public Function getAmountInWords(strAmount As String) As String
    Dim strIntPart          As String
    Dim strDecPart          As String
    Dim strCroresPart       As String
    Dim strLakhsPart        As String
    Dim strThousandsPart    As String
    Dim strHundredsPart     As String
    Dim strTensPart         As String
    Dim strOnesPart         As String
    Dim strDecTensPart      As String
    Dim strDecOnesPart      As String
    Dim strAmtWords         As String
    Dim dblIntPart          As Double
    Dim intDecPart          As Integer
    Dim strDecWords         As String
    Dim iErr As Integer

    'handle for typemismatch error
    '??Err.Clear
    '??On Error Resume Next
    On Error Goto BadError
    strAmount = CDbl(strAmount)
    '??If Err.Number = "13" Then
    '??    getAmountInWords = ""
    '??    Exit Function
    '??End If
    '??Err.Clear
    strAmount = Format(Trim(strAmount), "000000000.00")

    'if the value is negative,zero above the limit then give error message
    If Val(strAmount) < 0 Then
        getAmountInWords = ""
        Exit Function
    ElseIf Val(strAmount) = 0 Then
        getAmountInWords = "Rupees Zero"
        Exit Function
    ElseIf Val(strAmount) > 999999999.99 Then
        getAmountInWords = ""
        Exit Function
    End If

    'store the integer and decimal parts separately
    strIntPart = Mid(strAmount, 1, 9)
    strDecPart = Mid(strAmount, 11, 2)

    'store the individual places in variables
    strCroresPart = Mid(strIntPart, 1, 2)
    strLakhsPart = Mid(strIntPart, 3, 2)
    strThousandsPart = Mid(strIntPart, 5, 2)
    strHundredsPart = Mid(strIntPart, 7, 1)
    strTensPart = Mid(strIntPart, 8, 1)
    strOnesPart = Mid(strIntPart, 9, 1)
    strDecTensPart = Mid(strDecPart, 1, 1)
    strDecOnesPart = Mid(strDecPart, 2, 1)

    strAmtWords = ""
    'To make the Crores Part
    If Val(strCroresPart) <> 0 Then
        strAmtWords = strAmtWords & getCroresPart(strCroresPart)
    End If

    'To make the Lakhs Part
    If Val(strLakhsPart) <> 0 Then
        strAmtWords = strAmtWords & getLakhsPart(strLakhsPart)
    End If

    'To make the Thousands Part
    If Val(strThousandsPart) <> 0 Then
        strAmtWords = strAmtWords & getThousandsPart(strThousandsPart)
    End If

    'To make the hundreds Part
    If Val(strHundredsPart) <> 0 Then
        strAmtWords = strAmtWords & getOnesColumn(Format(strHundredsPart, "00")) & " Hundred "
    End If

    'To make Tens and Ones part
    If Val(strTensPart & strOnesPart) <> 0 And Val(strAmount) > 100 Then
        strAmtWords = strAmtWords & "and " & getTensOnesPart(strAmount, strTensPart, strOnesPart)
    Else
        strAmtWords = strAmtWords & getTensOnesPart(strAmount, strTensPart, strOnesPart)
    End If

    strDecWords = ""
    'To make Tens and Ones part in the decimal part
    If Val(strDecTensPart & strDecOnesPart) <> 0 Then
        strDecWords = strDecWords & getTensOnesPart(Val(strAmount), strDecTensPart, strDecOnesPart)
    End If

    'If both integer and decimal part are not Zero then add Rupees and Paise only
    If Val ...
(more)
edit flag offensive delete link more

Comments

thank you for the working code! helped a lot!

LuckySaiyo gravatar imageLuckySaiyo ( 2015-02-26 07:58:14 +0100 )edit

Question Tools

1 follower

Stats

Asked: 2012-03-14 20:07:38 +0100

Seen: 8,830 times

Last updated: Feb 22 '13