Results 1 to 5 of 5

Thread: Set decimal automatically

  1. #1
    Member
    Real Name
    David Fricke
    Join Date
    Sep 2011
    Location
    Kenosha, WI
    Posts
    385

    Default Set decimal automatically

    I'm entering a number into a field and I want the decimal point to automatically land 2 positions over.

    For example:
    User enters: 2999
    Field Displays: 29.99

    All doing without hitting the decimal point key.

    I've found a few threads on this but they're from 2008. I figure Alpha might have come up with a way to do this that I'm not seeing. This is similar to the setting on a calculator for accounting so you can skip the . key and it automatically puts it where you want it.

    Any help would be much appreciated.

  2. #2
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,046

    Default Re: Set decimal automatically

    You could use Client side formatting with a "Custom" Format definition. In the Format definition the radio button should be set to Number and your Parse Out could be...

    Code:
    data = (data/100).toFixed(2)

  3. #3
    Member
    Real Name
    David Fricke
    Join Date
    Sep 2011
    Location
    Kenosha, WI
    Posts
    385

    Default Re: Set decimal automatically

    Almost. When I go back to the field, it's rounding another 2 spaces to the left.

    If I enter say 49599, it shows 495.99. When I refresh that page it rounds it to 4.96. So it's rounding to the left again.

  4. #4
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,046

    Default Re: Set decimal automatically

    Indeed. I didn't test going back in and out after the decimal was set. By the in-line doc I thought the decimal symbols got stripped out. I guess everything else gets removed except for the decimal.

    So... change the Type to String. This leaves the incoming value alone. Then use this code in Parse Out...

    Code:
    var noDec = data.replace(".",'')
    data = (noDec/100).toFixed(2)
    Or... to be a little safer if you're using other symbols, such as thousands separator... leave the Type as Number and use this code...

    Code:
    var noDec = parseInt(data.toString().replace(".",''))
    data = (noDec/100).toFixed(2)
    Alpha converts the string into a number removing everything except the decimal. We then convert the number to a String, remove the decimal, convert the number to an integer and put the decimal back in.
    Last edited by Davidk; 11-08-2018 at 01:40 PM.

  5. #5
    Member
    Real Name
    David Fricke
    Join Date
    Sep 2011
    Location
    Kenosha, WI
    Posts
    385

    Default Re: Set decimal automatically

    That worked. Thanks! I was putting that /100 everywhere and couldn't quite get it to work right.

Similar Threads

  1. Decimal placement
    By PaulJK in forum Database Design
    Replies: 8
    Last Post: 04-24-2013, 05:15 PM
  2. Decimal Bug?
    By mazatec in forum Alpha Five Version 8
    Replies: 2
    Last Post: 08-16-2007, 09:16 AM
  3. automatically place decimal point
    By John Cunradi in forum Alpha Five Version 5
    Replies: 16
    Last Post: 06-19-2004, 05:39 PM
  4. HEX to Decimal
    By Keith Regan in forum Alpha Five Version 5
    Replies: 2
    Last Post: 08-15-2003, 06:09 AM
  5. decimal problem
    By Birol Gezici in forum Alpha Five Version 4
    Replies: 7
    Last Post: 08-11-2001, 09:43 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •