1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Truncating numbers

  1. Mar 21, 2009 #1
    Write a Matlab Function file that takes one integer in and converts it to an integer with only 5 significant digits.
    Eg Trunc(123)--------ans=123
    Tunc(123345678) ----ans=12345e+03
    ----------------------------------------------------------------------------------------

    My thoughts
    First see that the max number that doesn't get truncated is 99999.

    set up some logic
    if n>99999
    insert logic
    else
    n=n
    (n is the value passed into the function).
    Can anyone give us a hand?????
    Or suggest another approach
     
  2. jcsd
  3. Mar 22, 2009 #2
    One idea might be to use modulus and divide repeatedly to collect the digits of the integer in an array.

    n = 12345678

    then
    a(0) = 8
    a(1) = 7
    ...
    a(7) = 1

    Then scan down the array and either truncate or round the integer in the array. This is similar to the binary coded decimal arithmetic some computers have used.
     
  4. Mar 22, 2009 #3

    MATLABdude

    User Avatar
    Science Advisor

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Truncating numbers
  1. Ions number (Replies: 11)

  2. Number of particles (Replies: 4)

  3. Quantum numbers (Replies: 3)

  4. Number of protons (Replies: 1)

  5. Quantum numbers (Replies: 3)

Loading...