Home » questions » visual basic - how to get the first digit of a number without rounding off if the second digit is 5

visual basic - how to get the first digit of a number without rounding off if the second digit is 5

2006-08-08 21:45:12, Category: Programming & Design
456789 = 5 when 456789/100000 i want to get 4 and not 5

Answers

  1. Dyana

    On 2006-08-08 22:20:34


    formerly u declare the number as integet rite? u can create another function and put the number into array and declare the array as 'char'. For example: char singleNo char arrayNo[ ] = '456789' for(int i = 0; i < arrayNo[maxChar]; i ++) { singleNo = arrayNo[0]; } i am not sure this is the correct one or not but the basic idea is, u need to change the number (or declare the number as 'char' or string) and make it as character, then get the first number (or char) in the array. Maybe u can try first. i can't remember the code i made before but the idea is like that. Good luck =)
  2. Blake A

    On 2006-08-08 21:54:28


    Use Fix(). Example. variable = Fix(19.9999999) The value of variable will be 19
  3. Bogdan

    On 2006-08-08 21:56:56


    I don't know Visual basic too well but, in any programming language, I'd first transform the number into a string variable, then get the first character. After that, transform the string or character variable which contains the first digit of your number, back into an integer variable. This should work in any programming language...
  4. cHORPO

    On 2006-08-08 23:34:34


    Defenetly the Blake's answer is correct because the Fix function returns the integer part of a specified number.