Format the float type. retain the first decimal point and the float decimal point.

Source: Internet
Author: User

Format the float type. retain the first decimal point and the float decimal point.

 

1 "" exercise: 2. James's score has increased from 72 points last year to 85 points this year. Calculate the percentage point that James's score has improved. 3. format the string to display 'xx. x % ', only the first digit after the decimal point is retained: 4 "5 # NOTE: formatted float Type reserved digits output: 6 # (' % 0.1f' % r) -- (retain the first digit after the decimal point) 7 # ('% 0.2f' % r) -- (retain the second digit after the decimal point) 8 #-*-coding: UTF-8-*-9 def Check_Score (): 10 s1 = 7211 s2 = 8512 r = (s2-s1)/s1*10013 print ("James scores improved {} % ". format ('%. 1f' % r) 14 if _ name _ = '_ main _': 15 Check_Score ()

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.