Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: Crumenal en 21 Julio 2025, 09:30 am



Título: como poner los decimales correctamente?
Publicado por: Crumenal en 21 Julio 2025, 09:30 am
Código:
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
   double exa = 1E18;
   cout<<"+"<< setw(20)<<setfill ('-')<<""<<"+"<<setw(15)<<setfill ('-')<<""<<"+"<<setw(20)<<setfill ('-')<<""<<"+"<<endl;
   cout<<"|"<< setw(20)<<"Decimal"<<"|"<<setw(15)<<"Standard form"<<"|"<<setw(8)<<"prefex"<<"|"<<setw(5)<<"Abbreviation"<<"|"<<endl;
   cout<<"+"<< setw(20)<<setfill ('-')<<""<<"+"<<setw(15)<<setfill ('-')<<""<<"+"<<setw(20)<<setfill ('-')<<""<<"+"<<endl;
   cout<<"|"<<setw(20)<<fixed<<setprecision(0)<<exa<<"|"<<setw(15)<<left<<scientific<<exa<<"|"<<setw(8)<<"exa"<<"|"<<setw(10)<<"E"<<"|"<<endl;
   cout<<"+"<< setw(20)<<setfill ('-')<<""<<"+"<<setw(15)<<setfill ('-')<<""<<"+"<<setw(20)<<setfill ('-')<<""<<"+"<<endl;
   cout<<"|"<<setw(20)<<fixed<<setprecision(0)<<exa<<"|"<<setw(15)<<left<<scientific<<1E15<<"|"<<setw(8)<<"peta"<<"|"<<setw(10)<<"P"<<"|"<<endl;
   cout<<"+"<< setw(20)<<setfill ('-')<<""<<"+"<<setw(15)<<setfill ('-')<<""<<"+"<<setw(20)<<setfill ('-')<<""<<"+"<<endl;
   cout<<"|"<<setw(20)<<fixed<<setprecision(0)<<exa<<"|"<<setw(15)<<left<<scientific<<1E12<<"|"<<setw(8)<<"tera"<<"|"<<setw(10)<<"T"<<"|"<<endl;
   cout<<"+"<< setw(20)<<setfill ('-')<<""<<"+"<<setw(15)<<setfill ('-')<<""<<"+"<<setw(20)<<setfill ('-')<<""<<"+"<<endl;
   cout<<"|"<<setw(20)<<fixed<<setprecision(0)<<exa<<"|"<<setw(15)<<left<<scientific<<1E9<<"|"<<setw(8)<<"giga"<<"|"<<setw(10)<<"G"<<"|"<<endl;
   cout<<"+"<< setw(20)<<setfill ('-')<<""<<"+"<<setw(15)<<setfill ('-')<<""<<"+"<<setw(20)<<setfill ('-')<<""<<"+"<<endl;
   cout<<"|"<<setw(20)<<fixed<<setprecision(0)<<exa<<"|"<<setw(15)<<left<<scientific<<1E6<<"|"<<setw(8)<<"mega"<<"|"<<setw(10)<<"M"<<"|"<<endl;
   cout<<"+"<< setw(20)<<setfill ('-')<<""<<"+"<<setw(15)<<setfill ('-')<<""<<"+"<<setw(20)<<setfill ('-')<<""<<"+"<<endl;
   cout<<"|"<<setw(20)<<fixed<<setprecision(0)<<exa<<"|"<<setw(15)<<left<<scientific<<1E3<<"|"<<setw(8)<<"kilo"<<"|"<<setw(10)<<"k"<<"|"<<endl;
   cout<<"+"<< setw(20)<<setfill ('-')<<""<<"+"<<setw(15)<<setfill ('-')<<""<<"+"<<setw(20)<<setfill ('-')<<""<<"+"<<endl;
   cout<<"|"<<setw(20)<<fixed<<setprecision(0)<<exa<<"|"<<setw(15)<<left<<scientific<<1E2<<"|"<<setw(8)<<"hecto"<<"|"<<setw(10)<<"h"<<"|"<<endl;
   cout<<"+"<< setw(20)<<setfill ('-')<<""<<"+"<<setw(15)<<setfill ('-')<<""<<"+"<<setw(20)<<setfill ('-')<<""<<"+"<<endl;
   cout<<"|"<<setw(20)<<fixed<<setprecision(0)<<exa<<"|"<<setw(15)<<left<<scientific<<1E1<<"|"<<setw(8)<<"deca"<<"|"<<setw(10)<<"da"<<"|"<<endl;
   cout<<"+"<< setw(20)<<setfill ('-')<<""<<"+"<<setw(15)<<setfill ('-')<<""<<"+"<<setw(20)<<setfill ('-')<<""<<"+"<<endl;
   cout<<"|"<<setw(20)<<fixed<<setprecision(0)<<exa<<"|"<<setw(15)<<left<<scientific<<1<<"|"<<setw(8)<<"deci"<<"|"<<setw(10)<<"d"<<"|"<<endl;
   cout<<"+"<< setw(20)<<setfill ('-')<<""<<"+"<<setw(15)<<setfill ('-')<<""<<"+"<<setw(20)<<setfill ('-')<<""<<"+"<<endl;
   cout<<"|"<<setw(20)<<fixed<<setprecision(0)<<exa<<"|"<<setw(15)<<left<<scientific<<1E-1<<"|"<<setw(8)<<"centi"<<"|"<<setw(10)<<"c"<<"|"<<endl;
   cout<<"+"<< setw(20)<<setfill ('-')<<""<<"+"<<setw(15)<<setfill ('-')<<""<<"+"<<setw(20)<<setfill ('-')<<""<<"+"<<endl;
   cout<<"|"<<setw(20)<<fixed<<setprecision(0)<<exa<<"|"<<setw(15)<<left<<scientific<<1E-3<<"|"<<setw(8)<<"milli"<<"|"<<setw(10)<<"m"<<"|"<<endl;
   cout<<"+"<< setw(20)<<setfill ('-')<<""<<"+"<<setw(15)<<setfill ('-')<<""<<"+"<<setw(20)<<setfill ('-')<<""<<"+"<<endl;
   cout<<"|"<<setw(20)<<fixed<<setprecision(0)<<exa<<"|"<<setw(15)<<left<<scientific<<1E-6<<"|"<<setw(8)<<"micro"<<"|"<<setw(10)<<"?"<<"|"<<endl;
   cout<<"+"<< setw(20)<<setfill ('-')<<""<<"+"<<setw(15)<<setfill ('-')<<""<<"+"<<setw(20)<<setfill ('-')<<""<<"+"<<endl;
   cout<<"|"<<setw(20)<<fixed<<setprecision(0)<<exa<<"|"<<setw(15)<<left<<scientific<<1E-9<<"|"<<setw(8)<<"nano"<<"|"<<setw(10)<<"n"<<"|"<<endl;
   cout<<"+"<< setw(20)<<setfill ('-')<<""<<"+"<<setw(15)<<setfill ('-')<<""<<"+"<<setw(20)<<setfill ('-')<<""<<"+"<<endl;
   cout<<"|"<<setw(20)<<fixed<<setprecision(0)<<exa<<"|"<<setw(15)<<left<<scientific<<1E-12<<"|"<<setw(8)<<"pico"<<"|"<<setw(10)<<"p"<<"|"<<endl;
   cout<<"+"<< setw(20)<<setfill ('-')<<""<<"+"<<setw(15)<<setfill ('-')<<""<<"+"<<setw(20)<<setfill ('-')<<""<<"+"<<endl;
   cout<<"|"<<setw(20)<<fixed<<setprecision(0)<<exa<<"|"<<setw(15)<<left<<scientific<<"1E-15"<<"|"<<setw(8)<<"femto"<<"|"<<setw(10)<<"f"<<"|"<<endl;
   cout<<"+"<< setw(20)<<setfill ('-')<<""<<"+"<<setw(15)<<setfill ('-')<<""<<"+"<<setw(20)<<setfill ('-')<<""<<"+"<<endl;
   cout<<"|"<<setw(20)<<fixed<<setprecision(0)<<exa<<"|"<<setw(15)<<left<<scientific<<"1E-18"<<"|"<<setw(8)<<"atto"<<"|"<<setw(10)<<"a"<<"|"<<endl;
   cout<<"+"<< setw(20)<<setfill ('-')<<""<<"+"<<setw(15)<<setfill ('-')<<""<<"+"<<setw(20)<<setfill ('-')<<""<<"+"<<endl;


   return 0;

}




Título: Re: como poner los decimales correctamente?
Publicado por: Mr.Byte en 21 Julio 2025, 15:55 pm
Lo que sale de consola, para hacerlo un poco mas claro



+--------------------+---------------+--------------------+
|-------------Decimal|--Standard form|--prefex|Abbreviation|
+--------------------+---------------+--------------------+
|-1000000000000000000|1e+18----------|exa-----|E---------|
+--------------------+---------------+--------------------+
|1000000000000000000-|1e+15----------|peta----|P---------|
+--------------------+---------------+--------------------+
|1000000000000000000-|1e+12----------|tera----|T---------|
+--------------------+---------------+--------------------+
|1000000000000000000-|1e+09----------|giga----|G---------|
+--------------------+---------------+--------------------+
|1000000000000000000-|1e+06----------|mega----|M---------|
+--------------------+---------------+--------------------+
|1000000000000000000-|1e+03----------|kilo----|k---------|
+--------------------+---------------+--------------------+
|1000000000000000000-|1e+02----------|hecto---|h---------|
+--------------------+---------------+--------------------+
|1000000000000000000-|1e+01----------|deca----|da--------|
+--------------------+---------------+--------------------+
|1000000000000000000-|1--------------|deci----|d---------|
+--------------------+---------------+--------------------+
|1000000000000000000-|1e-01----------|centi---|c---------|
+--------------------+---------------+--------------------+
|1000000000000000000-|1e-03----------|milli---|m---------|
+--------------------+---------------+--------------------+
|1000000000000000000-|1e-06----------|micro---|?---------|
+--------------------+---------------+--------------------+
|1000000000000000000-|1e-09----------|nano----|n---------|
+--------------------+---------------+--------------------+
|1000000000000000000-|1e-12----------|pico----|p---------|
+--------------------+---------------+--------------------+
|1000000000000000000-|1E-15----------|femto---|f---------|
+--------------------+---------------+--------------------+
|1000000000000000000-|1E-18----------|atto----|a---------|
+--------------------+---------------+--------------------+