惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
F
Fortinet All Blogs
Martin Fowler
Martin Fowler
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
IT之家
IT之家
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客
V
V2EX
Vercel News
Vercel News
Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tailwind CSS Blog
I
InfoQ
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
H
Help Net Security
腾讯CDC
D
Docker
P
Proofpoint News Feed
GbyAI
GbyAI
博客园 - 三生石上(FineUI控件)
aimingoo的专栏
aimingoo的专栏

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Python'da int, float ve Decimal Formatlı Yazdırma Rehberi
Vebende Akademi · 2026-06-19 · via DEV Community

Vebende Akademi

Python'da int, float ve Decimal Formatlı Yazdırma Rehberi

Python'da sayısal verileri ekrana yazdırırken doğru formatlama yapmak oldukça önemlidir. Özellikle finansal uygulamalarda, raporlarda, veri analizlerinde ve kullanıcıya gösterilen çıktılarda sayıların okunabilir olması gerekir.

Bu çalışmada:

  • int (tam sayı)
  • float (ondalıklı sayı)
  • Decimal (yüksek hassasiyetli ondalıklı sayı)

tiplerinin nasıl formatlanacağını öğreneceğiz.


1. Integer (int) Formatlama

Temel Yazdırma

yas = 42

print(yas)

Çıktı:

42


Binlik Ayraç Kullanma

nufus = 85327641

print(f"{nufus:,}")

Çıktı:

85,327,641


Boşluk Doldurma

id_no = 125

print(f"{id_no:08}")

Çıktı:

00000125


Sağa Hizalama

sayi = 125

print(f"|{sayi:10}|")

Çıktı:

|       125|


Sola Hizalama

print(f"|{sayi:<10}|")

Çıktı:

|125       |


Ortaya Hizalama

print(f"|{sayi:^10}|")

Çıktı:

|   125    |


2. Float Formatlama

Temel Kullanım

fiyat = 123.456789

print(fiyat)

Çıktı:

123.456789


Virgülden Sonra 2 Basamak

fiyat = 123.456789

print(f"{fiyat:.2f}")

Çıktı:

123.46


Virgülden Sonra 4 Basamak

print(f"{fiyat:.4f}")

Çıktı:

123.4568


Binlik Ayraç ve Ondalık

maas = 125000.456

print(f"{maas:,.2f}")

Çıktı:

125,000.46


Yüzde Formatı

oran = 0.875

print(f"{oran:.2%}")

Çıktı:

87.50%


Bilimsel Gösterim

sayi = 123456789

print(f"{sayi:e}")

Çıktı:

1.234568e+08


Büyük Bilimsel Gösterim

print(f"{sayi:E}")

Çıktı:

1.234568E+08


3. Decimal Formatlama

Finansal işlemlerde float yerine Decimal kullanılması önerilir.

Decimal Tanımlama

from decimal import Decimal

fiyat = Decimal("1234.56789")

print(fiyat)

Çıktı:

1234.56789


2 Basamaklı Gösterim

from decimal import Decimal

fiyat = Decimal("1234.56789")

print(f"{fiyat:.2f}")

Çıktı:

1234.57


Binlik Ayraç Kullanımı

from decimal import Decimal

tutar = Decimal("123456789.98765")

print(f"{tutar:,.2f}")

Çıktı:

123,456,789.99


4. Finansal Formatlama

Muhasebe ve e-ticaret projelerinde sık kullanılır.

from decimal import Decimal

fiyat = Decimal("1499.99")
kdv = Decimal("0.20")

toplam = fiyat * (1 + kdv)

print(f"Ürün Fiyatı : {fiyat:,.2f} TL")
print(f"KDV         : %{kdv*100:.0f}")
print(f"Toplam      : {toplam:,.2f} TL")

Çıktı:

Ürün Fiyatı : 1,499.99 TL
KDV         : %20
Toplam      : 1,799.99 TL


5. Format Fonksiyonu Kullanımı

f-string dışında klasik yöntem:

sayi = 1234.5678

print("{:.2f}".format(sayi))

Çıktı:

1234.57


Binlik Ayraç

print("{:,.2f}".format(sayi))

Çıktı:

1,234.57


6. Türkçe Para Formatı

Python'ın varsayılan formatı Amerikan stilidir.

tutar = 1234567.89

formatli = f"{tutar:,.2f}"

formatli = (
    formatli
    .replace(",", "X")
    .replace(".", ",")
    .replace("X", ".")
)

print(formatli)

Çıktı:

1.234.567,89


7. Tüm Formatların Karşılaştırması

from decimal import Decimal

i = 1234567
f = 1234567.89123
d = Decimal("1234567.89123")

print(f"INT      : {i}")
print(f"INT      : {i:,}")

print(f"FLOAT    : {f}")
print(f"FLOAT    : {f:.2f}")
print(f"FLOAT    : {f:,.2f}")

print(f"DECIMAL  : {d}")
print(f"DECIMAL  : {d:.2f}")
print(f"DECIMAL  : {d:,.2f}")

print(f"YÜZDE    : {0.875:.2%}")
print(f"BİLİMSEL : {f:E}")

Çıktı:

INT      : 1234567
INT      : 1,234,567

FLOAT    : 1234567.89123
FLOAT    : 1234567.89
FLOAT    : 1,234,567.89

DECIMAL  : 1234567.89123
DECIMAL  : 1234567.89
DECIMAL  : 1,234,567.89

YÜZDE    : 87.50%
BİLİMSEL : 1.234568E+06


Profesyonel Projelerde En Sık Kullanılan Formatlar

Amaç Format
2 ondalık gösterim :.2f
4 ondalık gösterim :.4f
Binlik ayraç :,
Binlik + 2 ondalık :,.2f
Yüzde :.2%
Bilimsel gösterim :e
Büyük bilimsel gösterim :E
Sol hizalama <10
Sağ hizalama >10
Ortala ^10
Sıfır doldurma 08

Modern Python projelerinde sayı formatlama için en yaygın ve okunabilir yöntem f-string kullanımıdır. Finansal uygulamalarda ise hesaplama tarafında Decimal, görüntüleme tarafında ise f"{deger:,.2f}" kombinasyonu tercih edilir.