Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Truncating Numbers in Excel  (Read 2826 times)

0 Members and 1 Guest are viewing this topic.

grp

    Topic Starter


    Newbie

    • Experience: Experienced
    • OS: Windows 10
    Truncating Numbers in Excel
    « on: December 28, 2017, 02:07:20 PM »
    Hi All. I am trying to create a form that records data input from a barcode reader.  The problem that I have is that the original number on the barcode label contains 12 digits but I only require the last 6 to be displayed in my form. I have tried to re-configure the reader to truncate the number to 6 digits but this doesn't work so I was wondering if anyone can tell me whether there is a way to do this using Excel or a macro. I am using Excel 2010.
    Thank yo

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Truncating Numbers in Excel
    « Reply #1 on: December 28, 2017, 06:10:41 PM »
    You need to claify what you want to do.
    In Excel, the term 'truncate' is used to remove decimals that are not needed.
    https://exceljet.net/excel-functions/excel-trunc-function

    However, it may be taht what you want is not that.
    Give some example of before and after.

    Mark.



      Adviser
    • Forum Regular
    • Thanked: 67
      • Yes
    • Certifications: List
    • Computer: Specs
    • Experience: Experienced
    • OS: Windows 10
    Re: Truncating Numbers in Excel
    « Reply #2 on: December 28, 2017, 07:53:34 PM »
    RIGHT will do this for you.

    so macro code will look something like this;
    last6 = Right(mybarcode, 6)

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Truncating Numbers in Excel
    « Reply #3 on: December 28, 2017, 08:42:54 PM »
    Mark, that will work if it is a string.
    He did not say if the reade outputs text or a real number.

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: Truncating Numbers in Excel
    « Reply #4 on: December 28, 2017, 09:44:43 PM »
    Mark, that will work if it is a string.
    He did not say if the reade outputs text or a real number.

    -Barcode readers typically input text into the computer by emulating a keyboard. It will literally type the number digits into the computer when scanned. This would be the only way supported within Excel.

    -representing barcodes as numeric types would be ineffective as any sort of validation would need to convert it to a string to perform a number of string operations.

    -Even if the cell type in excel is numeric- which would be the likely default, It doesn't matter what type of data is in the cell. Excel will coerce the data to a text string if necessary. =RIGHT(ATAN(1)*4,7) gives "5358979" for example.

    -We know the cell type is almost certainly not numeric as a 12-digit numeric value will be shown via scientific notation which is useless as a barcode.
    I was trying to dereference Null Pointers before it was cool.

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Truncating Numbers in Excel
    « Reply #5 on: December 28, 2017, 11:59:42 PM »
    You are right. a 12 digit real number would be way beyhound normal usage.

    strollin



      Adviser
    • Thanked: 84
      • Yes
    • Certifications: List
    • Computer: Specs
    • Experience: Guru
    • OS: Windows 10
    Re: Truncating Numbers in Excel
    « Reply #6 on: December 29, 2017, 06:39:03 AM »
    Just in case you may have leading or trailing spaces in your barcode input, I would use this:
    last6 = Right(trim(mybarcode), 6)