Announcement

Collapse
No announcement yet.

Numbers to words

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • alvagar
    replied
    Very Good. It´s easy to use.

    Leave a comment:


  • kafecadm
    replied
    Hello Zubair:

    Glad you found it helpful. Keep on styding anyways that's never a waste.

    Regards

    Leave a comment:


  • Zubair Hussain
    replied
    Originally posted by kafecadm View Post
    Just so you guys know... there is a way in php already to spell out a number into letters

    PHP Code:
    <?php
    $f 
    = new NumberFormatter("en"NumberFormatter::SPELLOUT);
    echo 
    $f->format(123456);

    ?>
    So there's no need to create addditional functions.


    ROFL, I was studying hundreds of lines of code to understand how actually it is happening. Thanks for this time-saving technique man.

    It simply works for me.

    Leave a comment:


  • kafecadm
    replied
    Just so you guys know... there is a way in php already to spell out a number into letters

    PHP Code:
    <?php
    $f 
    = new NumberFormatter("en"NumberFormatter::SPELLOUT);
    echo 
    $f->format(123456);

    ?>
    So there's no need to create addditional functions.

    Leave a comment:


  • rababio
    replied
    I have found a way out. Thank alot.

    Leave a comment:


  • rababio
    replied
    Can anyone please help me on how to implement this on a pdf report in SC8. I imported the code on an internal library, called the it in my application and I am stuck. I have tried to use the function convertNum() in an OnRecord event but to no avail. Please help I have been struggling with this for weeks. thank you
    Last edited by rababio; 06-20-2016, 01:07 PM.

    Leave a comment:


  • Giu
    replied
    Originally posted by mumtaz View Post
    how to apply it in the report pdf


    Import the code on an internal library for example, and use the function convertNum(). Then, print on screeen the value converted

    Leave a comment:


  • mumtaz
    replied
    how to apply it in the report pdf

    Originally posted by Henriqueb View Post
    ScriptCase does not have a library to do this. But I found this code from Hugh Bothwell (http://stackoverflow.com/users/33258/hugh-bothwell) that can spell numbers up to nonillions:

    PHP Code:
    // Hugh Bothwell hugh_bothwell@hotmail.com
    // August 31 2001
    // Number-to-word converter

    $ones = array
    (
    "",
    " one",
    " two",
    " three",
    " four",
    " five",
    " six",
    " seven",
    " eight",
    " nine",
    " ten",
    " eleven",
    " twelve",
    " thirteen",
    " fourteen",
    " fifteen",
    " sixteen",
    " seventeen",
    " eighteen",
    " nineteen"
    );

    $tens = array
    (
    "",
    "",
    " twenty",
    " thirty",
    " forty",
    " fifty",
    " sixty",
    " seventy",
    " eighty",
    " ninety"
    );

    $triplets = array
    (
    "",
    " thousand",
    " million",
    " billion",
    " trillion",
    " quadrillion",
    " quintillion",
    " sextillion",
    " septillion",
    " octillion",
    " nonillion"
    );

    // recursive fn, converts three digits per pass
    function convertTri($num$tri)
    {
    global 
    $ones$tens$triplets;

    // chunk the number, ...rxyy
    $r = (int) ($num 1000);
    $x = ($num 100) % 10;
    $y $num 100;

    // init the output string
    $str "";

    // do hundreds
    if ($x 0)
    $str $ones[$x] . " hundred";

    // do ones and tens
    if ($y 20)
    $str .= $ones[$y];
    else
    $str .= $tens[(int) ($y 10)] . $ones[$y 10];

    // add triplet modifier only if there
    // is some output to be modified...
    if ($str != "")
    $str .= $triplets[$tri];

    // continue recursing?
    if ($r 0)
    return 
    convertTri($r$tri+1).$str;
    else
    return 
    $str;
    }

    // returns the number as an anglicized string
    function convertNum($num)
    {
    $num = (int) $num// make sure it's an integer

    if ($num 0)
    return 
    "negative".convertTri(-$num0);

    if (
    $num == 0)
    return 
    "zero";

    return 
    convertTri($num0);

    More info will be found here: http://marc.info/?l=php-general&m=99928281523866&w=2

    Leave a comment:


  • higinio
    replied
    Thank You Henriqueb.

    Leave a comment:


  • Henriqueb
    replied
    ScriptCase does not have a library to do this. But I found this code from Hugh Bothwell (http://stackoverflow.com/users/33258/hugh-bothwell) that can spell numbers up to nonillions:

    PHP Code:
    // Hugh Bothwell hugh_bothwell@hotmail.com 
    // August 31 2001
    // Number-to-word converter

    $ones = array
    (
       
    "",
       
    " one",
       
    " two",
       
    " three",
       
    " four",
       
    " five",
       
    " six",
       
    " seven",
       
    " eight",
       
    " nine",
       
    " ten",
       
    " eleven",
       
    " twelve",
       
    " thirteen",
       
    " fourteen",
       
    " fifteen",
       
    " sixteen",
       
    " seventeen",
       
    " eighteen",
       
    " nineteen"
    );

    $tens = array
    (
       
    "",
       
    "",
       
    " twenty",
       
    " thirty",
       
    " forty",
       
    " fifty",
       
    " sixty",
       
    " seventy",
       
    " eighty",
       
    " ninety"
    );

    $triplets = array
    (
       
    "",
       
    " thousand",
       
    " million",
       
    " billion",
       
    " trillion",
       
    " quadrillion",
       
    " quintillion",
       
    " sextillion",
       
    " septillion",
       
    " octillion",
       
    " nonillion"
    );

    // recursive fn, converts three digits per pass
    function convertTri($num$tri
    {
       global 
    $ones$tens$triplets;

    // chunk the number, ...rxyy
       
    $r = (int) ($num 1000);
       
    $x = ($num 100) % 10;
       
    $y $num 100;

    // init the output string
       
    $str "";

    // do hundreds
       
    if ($x 0)
          
    $str $ones[$x] . " hundred";

    // do ones and tens
       
    if ($y 20)
          
    $str .= $ones[$y];
       else
          
    $str .= $tens[(int) ($y 10)] . $ones[$y 10];

    // add triplet modifier only if there
    // is some output to be modified...
       
    if ($str != "")
          
    $str .= $triplets[$tri];

    // continue recursing?
       
    if ($r 0)
          return 
    convertTri($r$tri+1).$str;
       else
          return 
    $str;
    }

    // returns the number as an anglicized string
    function convertNum($num
    {
       
    $num = (int) $num// make sure it's an integer

       
    if ($num 0)
          return 
    "negative".convertTri(-$num0);

       if (
    $num == 0)
          return 
    "zero";

       return 
    convertTri($num0);

    More info will be found here: http://marc.info/?l=php-general&m=99928281523866&w=2

    Leave a comment:


  • higinio
    started a topic Numbers to words

    Numbers to words

    I want convert a number amount to words
    Can anyone heplme?
Working...
X