|
|
|
|||||||
| Development Discussions All developers who are coding games may stop by here for any help, suggestions, and everything development related. |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Member
$zB: 335
Donate |
So right now I have it changing volume control with:
MediaPlayer.Volume -= .03f; And It's 'Printing' It with: String Volume = "Volume: " + MediaPlayer.Volume.ToString(); Nothing is Wrong With the code, but when you adjust the volume it goes into odd decimals. Pressing down then up will give me .9999 instead of 1. My question is, how could I code this to Not only stop going into decimals but make it 1-20 (in increments of 1) instead of 0 to 1 (in increments of .03). Thanks. ![]() Another little problem I have, I have DateTime.Now.ToString() Being 'printed' and it is a few hours off. How could I adjust this? (in game, pressing left and right)
__________________
Invisible Text. =P To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts. |
|
|
|
| Remove Advertisements Sponsored Links | |
Advertisement |
|
|
|
#2 (permalink) |
|
Jr. Member
Join Date: May 2008
Location: Seattle, WA
Posts: 398
Reputation: 60
Donate |
Welcome to floating point inaccuracy.
On any computer that works in binary you will always see this when doing floating point arithmetic. The only way to solve it is use integers . Something like:int myVolume = 100; MediaPlayer.Volume = myVolume / 100f; string volume = "Volume: " + myVolume + "%"; Then you'll always see an even number displayed as a percentage of the volume. But basically when it comes to floating point math on a computer, you are never guaranteed for it to be exact. That's just how it is.
__________________
Nick Gravelyn Microsoft MVP - DirectX/XNA To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
|
|
|
|
|
#4 (permalink) | |
|
Member
$zB: 335
Donate |
Quote:
Worked awesome! If you did mean to put == (2 of them) there, Yes I suppose that would work... But that's a hell of a lot of code because it did it for every increment.
__________________
Invisible Text. =P To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts. |
|
|
|
|
![]() |
| Thread Tools | |
|
|
| |