[.net] Conversion UINT' to 'FLOAT
Anyone know of a any way to convert UINT to FLOAT. I knew of a function, but I seem to have forgot it.
Thanks.
I believe it is System.Convert.ToDecimal() For anything else take a look at the Convert Class. If that's not it, this is then (I hope [lol]). Well I mean go from UINT->DECIMAL->FLOAT, but there's probabally a simpler way someone more familiar with .Net knows of.
You should be able to do regular typecasting:
I mean if you are going from UINT to FLOAT, you are just adding on a .0000000 because an UINT is a whole number. That's what the typecasting does for you.
Thanks for pointing that out. I don't like the renaming convention that takes place in .Net [headshake]. Couldn't find any references to float.
// method 1unsigned int value = 25;float myNumber = (float)value;// method 2unsigned int value = 25;float myNumber = static_cast<float>(value);
I mean if you are going from UINT to FLOAT, you are just adding on a .0000000 because an UINT is a whole number. That's what the typecasting does for you.
Quote:Original post by Del Snd of Thndr
You might want to check out:
System.Convert.ToSingle()
Thanks for pointing that out. I don't like the renaming convention that takes place in .Net [headshake]. Couldn't find any references to float.
"cannot convert from 'float' to 'FLOAT *__w64 '"
I get this error when I use typecasting, forgot about that.
I get this error when I use typecasting, forgot about that.
Where you are getting that error, you should be using &variable, rather than just variable. It's saying it cannot convert from a float to a float pointer. Can you post some code so we can see exactly what you are doing.
I am simply getting some info from directx about a image, taking its height then the direct3d surface and calculating the x and y values for a direct3d vector, that way I can set scale for my images. I had issues with scaling and thought of fixing it this way.
&m_Scale.x = static_cast<float>(imageInfo.Width / desc.Width);
&m_Scale.y = static_cast<float>(imageInfo.Height / desc.Height);
I know about the pointer and such, but when I did it I got the error. Thats the problem it has to be a pointer and make refrences else all my objects will be the same shape. Removing the pointer makes it work but only one sprite shows.
&m_Scale.x = static_cast<float>(imageInfo.Width / desc.Width);
&m_Scale.y = static_cast<float>(imageInfo.Height / desc.Height);
I know about the pointer and such, but when I did it I got the error. Thats the problem it has to be a pointer and make refrences else all my objects will be the same shape. Removing the pointer makes it work but only one sprite shows.
Any reason you are trying to assign to the address of those variables?
Could you not just go
m_Scale.x = (float)(imageInfo.Width / desc.Width);
m_Scale.y = (float)(imageInfo.Height / desc.Height);
That's how I would do it
Could you not just go
m_Scale.x = (float)(imageInfo.Width / desc.Width);
m_Scale.y = (float)(imageInfo.Height / desc.Height);
That's how I would do it
Ahh that sounds like a DirectX problem as for why not both sprites are showing. As for the code:
Should be what you need if imageInfo, desc, and m_Scale are not pointers. What are the variable declarations of all those variables that you use? Can you list m_Scale, m_Scale.x, m_Scale.y, imageInfo, imageInfo.Width, desc, desc.Width, imageInfo.Height, and desc.Height.
m_Scale.x = static_cast<float>(imageInfo.Width / desc.Width);m_Scale.y = static_cast<float>(imageInfo.Height / desc.Height);
Should be what you need if imageInfo, desc, and m_Scale are not pointers. What are the variable declarations of all those variables that you use? Can you list m_Scale, m_Scale.x, m_Scale.y, imageInfo, imageInfo.Width, desc, desc.Width, imageInfo.Height, and desc.Height.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement