Getting integer values (not double-precision) from a slider (trackbar)
-
Does anybody knows a way to get integer values from the slider control, instead of double-precision values? My slider control is from 0 to 255 and I want use it as way of getting an integer value, to be able to send it throw the serial port to the arduino duemilanove.
-
Does anybody knows a way to get integer values from the slider control, instead of double-precision values? My slider control is from 0 to 255 and I want use it as way of getting an integer value, to be able to send it throw the serial port to the arduino duemilanove.
Can't you just cast the double to an int? Or better yet, Round it to the nearest whole number then cast it to an int?
double someVal = 0.5782;
int intVal = (int)Math.Round(someVal);My current favourite quote is: Punch them in the face, see what happens!
-SK Genius
-
Does anybody knows a way to get integer values from the slider control, instead of double-precision values? My slider control is from 0 to 255 and I want use it as way of getting an integer value, to be able to send it throw the serial port to the arduino duemilanove.
In my books TrackBar.Value[^] is an integer. :confused:
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
-
In my books TrackBar.Value[^] is an integer. :confused:
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
I'm using C# but in WPF Application (XAML) the snippet using Math.Round works perfectly
-
I'm using C# but in WPF Application (XAML) the snippet using Math.Round works perfectly
you should have said so. it is the (int) cast that solves it, rounding/ceiling/flooring is up to you. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
-
you should have said so. it is the (int) cast that solves it, rounding/ceiling/flooring is up to you. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
It doesn't matter to make a (int) cast, since the value of slider is to be stored in a label. In XAML, label.Content is of type 'object'
-
It doesn't matter to make a (int) cast, since the value of slider is to be stored in a label. In XAML, label.Content is of type 'object'
I'm fine for now. I have no more questions. Thanks for everyone!
-
It doesn't matter to make a (int) cast, since the value of slider is to be stored in a label. In XAML, label.Content is of type 'object'
:confused: :confused: :confused: :confused: you asked for an integer value, see the subject line.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
-
:confused: :confused: :confused: :confused: you asked for an integer value, see the subject line.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
Here is the point: Getting a number from the slider control and make it integer (a.k.a. removing fractional part) so that I can send it through the serial port When speaking about integers, it doesn't mean to be a 'int' variable, but in other words, a natural number