Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: How to convert a number to have just two decimals?  (Read 2925 times)

0 Members and 1 Guest are viewing this topic.

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
How to convert a number to have just two decimals?
« on: August 04, 2010, 02:27:51 PM »

I'm trying a conversion to percentage but there are too many decimals on the result like 55.500000

Code: Text
  1. var MaxScore = 1000;
  2. var ScoreTemp = 555;
  3. var ScoreCalc = (ScoreTemp / MaxScore) * 100; // returns 55.500000
  4. //ScoreCalc = ToInt(ScoreCalc); // returns 55
  5.  

How can I change it to be just 55.50 ?

Thanks
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: How to convert a number to have just two decimals?
« Reply #1 on: August 05, 2010, 01:41:57 PM »

WME doesn't have any built-in facilities for formatting decimal numbers, so one would have to use the String object and to the hard work manually.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
Re: How to convert a number to have just two decimals?
« Reply #2 on: August 07, 2010, 12:35:26 AM »

Thanks, I went with the rough ToInt conversion instead then. Less is more  ::slug
Logged
 

Page created in 0.047 seconds with 38 queries.