SOLVED: Using a Float variable reminder

Started by Slasher, Sun 04/06/2017 09:28:24

Previous topic - Next topic

Slasher

Hi,

I have not used variable Float in a long long time and need reminding...

I want to be able to keep a track of weight... I have made WeightAdded Float variable and set it to 0.00.

You place coins on a scale. Each time you add a coin the scales show it's weight via a label.

As you add coins the weight increase.

Do I, as like an int variable adjust weight by:
Code: ags

WeightAdded +=1.2  // for exmple.


A label will keep track of the total weight..
Code: ags

TotalWeight.Text=(String.Format("%d",WeightAdded));


Am I on the right track?

Cheers


Crimson Wizard

#1
You need to use "%f" when printing floats.

Also, there is a way to control how many digits after "." you want printed, using format like "%.2f" - prints 2 digits after point max.

Slasher

#2
Cheers Crimson..

Got the 'cannot change int to float'... Text is not a public member of Float..

???

EDIT: i think I forget to add the correct Label.. trying...
Code: ags

LWEIGHT.Text=(String.Format("%.2f",WeightAdded));  //seems to work ok


Cheers Crimson (nod)



SMF spam blocked by CleanTalk