Ultimate Amiga

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: How to format my decimal variable?  (Read 3851 times)

0 Members and 3 Guests are viewing this topic.

xboxisfinished

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 205
  • Generic Amiga User
    • gamemakermagazine.com
How to format my decimal variable?
« on: May 21, 2015, 08:04:44 PM »

I have set a timer with # float on it. When the timer goes down in decimal point -0.01 it goes down fine

2.00, 1.99, 1.98, 1.97, etc...respectively! Sweet! Problem I have when it reaches 0.98, decimal then it adds 0.980000000 on it
how do I fix it so it contain the format

#0.00 only?

Thanks in advance.
Logged

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: How to format my decimal variable?
« Reply #1 on: May 23, 2015, 03:03:59 PM »

Fixed point is easier to work with than floating point.  Just make an integer variable that is 100 times greater and then print n/100;".";n mod 100

If you must use floating point, you'll have to use string manipulation to avoid the rounding error.
Logged

xboxisfinished

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 205
  • Generic Amiga User
    • gamemakermagazine.com
Re: How to format my decimal variable?
« Reply #2 on: May 24, 2015, 03:46:38 AM »

Fixed point is easier to work with than floating point.  Just make an integer variable that is 100 times greater and then print n/100;".";n mod 100

If you must use floating point, you'll have to use string manipulation to avoid the rounding error.

Assuming I want to use the string manipulation. Can you give me an example of how to do that? Like a format string manipulation?

Thanks in advance.
Logged

Sidewinder

  • Forum Mod
  • A600
  • *****
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 155
    • http://www.liquido2.com/
Re: How to format my decimal variable?
« Reply #3 on: May 24, 2015, 05:03:34 PM »

If you are using the Print instruction to do this output you can add a Using directive to it and specify the exact format of the output:

Print Using "#.##";TIMER#

This should limit the output to 1 digit before the decimal point and two digits after.
Logged
- Sidewinder

xboxisfinished

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 205
  • Generic Amiga User
    • gamemakermagazine.com
Re: How to format my decimal variable?
« Reply #4 on: May 24, 2015, 11:41:03 PM »

If you are using the Print instruction to do this output you can add a Using directive to it and specify the exact format of the output:

Print Using "#.##";TIMER#

This should limit the output to 1 digit before the decimal point and two digits after.

Thank you so much! :)
Logged

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: How to format my decimal variable?
« Reply #5 on: May 26, 2015, 06:04:16 PM »

Huh.  I looked into the online manual for print using and could not find it.
Logged

xboxisfinished

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 205
  • Generic Amiga User
    • gamemakermagazine.com
Re: How to format my decimal variable?
« Reply #6 on: May 26, 2015, 06:38:01 PM »

Huh.  I looked into the online manual for print using and could not find it.

It is there! It works!! Weeeee!!!
Logged

Sidewinder

  • Forum Mod
  • A600
  • *****
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 155
    • http://www.liquido2.com/
Re: How to format my decimal variable?
« Reply #7 on: May 26, 2015, 06:39:45 PM »

Yeah, it took me some time to find it too.  It's under "Using" in the index, section 5.6.13.
Logged
- Sidewinder
Pages: [1]   Go Up
 

TinyPortal 2.2.2 © 2005-2022