How to remove the last number from an integer?

Asked

Viewed 259 times

11

How can I remove the last number from an integer?

Ex:

int value = 123456789;

int newValue = 12345678;

Note that the new value does not have 9.

I know it would be possible to switch to a string and use the substring(), but would like something without having to convert to string and then have to change again to int.

  • 3

    Multiplying by 0.1?

  • 1

    @Articuno and making cast for whole back

1 answer

17


  • Not that I care, just curiosity, what runs faster, turn into string and take everything but the last part, or do the math?

  • 4

    Mathematics always, with great difference, even if it was already string and didn’t need to convert, and need to, so it gets monster.

  • Okay, thank you very much.

  • Ual... simple and fantastic.

  • For the entire division: https://answall.com/a/198271/64969 https://answall.com/a/43612/64969

  • 2

    The . NET Fiddle link example code is not compiling.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.