Removing decimal points(solved)

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Removing decimal points(solved)

#1 Post by JQuartz » Fri Jan 02, 2009 10:14 pm

How do you remove decimal points from integers. Something like 1.0 becoming 1.
Last edited by JQuartz on Sat Jan 03, 2009 10:03 am, edited 1 time in total.
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

iichan_lolbot
Veteran
Posts: 206
Joined: Tue Dec 30, 2008 9:18 am
Projects: iichan erogame
Contact:

Re: Removing decimal points

#2 Post by iichan_lolbot » Sat Jan 03, 2009 9:01 am

Code: Select all

    float = 10.81
    text = "%d" % float
text now contains 10 (not 11).
//1.0...1.99 ->1

If you want the values to be rounded properly, add 0.5 to them:

Code: Select all

    float = 10.81
    text = "%d" % (float+0.5)
text now contains 11.
//0.50...1.49 ->1

User avatar
JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Removing decimal points

#3 Post by JQuartz » Sat Jan 03, 2009 9:53 am

Thanks a lot. It works. I owe you one iichan_lolbot!
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

Post Reply

Who is online

Users browsing this forum: No registered users