keep only last digit of integer?
758
3
0
olivierth
Member
1004 posts
Joined: April 2017
Offline
Oct. 20, 2021 2:23 p.m.
Hi! I'm doing some vex to calculate UV placement based on a UDIM numbers that I choose. I would like to know how I can have an integer like 1023 and only keep the last digit (3 ).
olivierth
Member
1004 posts
Joined: April 2017
Offline
Oct. 20, 2021 2:30 p.m.
Ok, it's not pretty but I did this:
float udim = float (detail (1 , "chosenUdim" , 0 ));
float uOffset = udim - (rint (udim / 10 ) * 10 ) - 1 ;
Edited by olivierth - Oct. 20, 2021 14:31:06
tamte
Member
8444 posts
Joined: July 2007
Offline
Oct. 20, 2021 2:33 p.m.
you can do this for example
int number = 1023 ;
int last_digit = number % 10 ;
since reminder of dividing by 10 would always be 0-9 so the last digit
at least for positive integers, which UDIMs are
Edited by tamte - Oct. 20, 2021 14:34:39
Tomas Slancik FX Supervisor Method Studios, NY
olivierth
Member
1004 posts
Joined: April 2017
Offline
Oct. 20, 2021 2:48 p.m.
Ah!! That's some outside-of-the-box thinkin'! Also, my example was flawed. Instead of using "rint " I should have used "int " Thanks!
Edited by olivierth - Oct. 20, 2021 14:49:02