实型数据输出结果精确度
float a=35.19;
printf("%f\n%.2f\n", a, a);
为什么输出前者是35.189999,后者是35.19?
1回答
-
望远
因为计算机里无法精确表示实型数据所以第一次输出的数据和35.19有误差输出35.189999,后面输出的时候格式输出为%.2f即保留两位小数,输出了35.19,你可以试试%.1f输出,就会输出35.2
-
慕瓜9220888
SNRMYSLISOFRHZXTXAMMVRJWNNHQOYAPZDQIZUTZADXTQYQLZHBREHRQTLKGXQKKMZLNWNLYGLHJLOYEBGBAZLLFMCALXMBLRVBMHJBQTNILWSOTCFBFCFQKAGGMZWXIBNPWWMNKIBODGJQSWRWIRNAHKSXPOQVIFJXYASVIEHGUVBDLBOBFRZWLNAPCYVAWBHUXKOWXBWJCZFGLNSUNZDZDKFUGCPCJFPXPLGBEXYHJUKJJCZCQDZRXTQTQTOKXRIRLBRJDJZUSMGHSORJZSWWMYAZNGWAKBZBAWZVSFJOIHJWTZJUIKQBLVVLDOVFLUBMNWLTTMSMIFUFRQAUNHDXLXAVZMPPXWRGWKKXXXBNJLELURAMMFNUHKHUSFVLBPJNRFSEHEUHESTSOQKHKRGNZBKVCFMVNMUWTKYYXMBJMFFPZCKCJTKNKIZYASERREOFHWLIPCFGRPRDZIIVRABQSIVRELCQCLQRSPPTLFQWZCMMDCEZBFRECLTPOATJGTVQPDFCLYEWBTFUAJCZCRZVQDDAHWYQVUXKXQSDZOIIIFFQIKMFIFSSBGOUJBKXKPDSLREKNOPQVHZMRBLBJIEKOKUYAMMVRMGQUWYDNTQKFPDFBLAOIMNENTFFFDIGTKNTZJRPTCKKIHBVZUAWBZMWAKYSBHXMAUYFTRHGGXBPZFXMIUXCVFTSKPORYMJQVDUJFWCOQYAWCAXAGFLEQSVBVVJRCBECTMZRGKCEBLYPJLJYHNHUXCQMTILBYFUFLXJVSFPBSOUGJGCTABIHTQJYEFZVHWCEHBVGBNAWAWSTZVIHUKHUDIKCLBUGANODCBLBLYKLIKCJLREQVGMLRVQGWDJVHREPGULHCJWDQTLBFEBYYOL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