{"id":706,"date":"2024-07-30T20:21:18","date_gmt":"2024-07-30T18:21:18","guid":{"rendered":"https:\/\/blog.sutilweb.eu\/?page_id=706"},"modified":"2024-07-30T20:21:18","modified_gmt":"2024-07-30T18:21:18","slug":"003-objeto-math","status":"publish","type":"page","link":"https:\/\/sutilweb.eu\/index.php\/lenguajes\/javascript\/javascript-practico\/06-objetos-y-funciones-del-lenguaje\/003-objeto-math\/","title":{"rendered":"003. Objeto Math"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">El objeto <strong><em>Math<\/em> <\/strong>nos ayuda mucho sobre todo si tenemos que hacer algunas operaciones matem\u00e1ticas especiales, se trata del objeto <strong><em>Math<\/em><\/strong>. Se trata de un objeto est\u00e1tico, hay que invocar directamente al prototipo. Veamos un ejm.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Ejm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&nbsp; &lt;head&gt;\n&nbsp; &nbsp; &lt;meta charset=\"UTF-8\" \/&gt;\n&nbsp; &nbsp; &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" \/&gt;\n&nbsp; &nbsp; &lt;title&gt;Objeto Math&lt;\/title&gt;\n&nbsp; &lt;\/head&gt;\n\n&nbsp; &lt;body&gt;\n&nbsp; &nbsp; &lt;h1&gt;Objeto Math&lt;\/h1&gt;\n\n&nbsp; &nbsp; &lt;script&gt;\n&nbsp; &nbsp; &nbsp; console.log(Math); \/\/ Muestra todos los m\u00e9todos y propiedades de Math\n&nbsp; &nbsp; &nbsp; console.log(Math.abs(-7.8)); \/\/ Devuelve el valor absoluto de un n\u00famero\n&nbsp; &nbsp; &nbsp; console.log(Math.ceil(7.8)); \/\/ Redondea al n\u00famero entero mayor inmediato\n&nbsp; &nbsp; &nbsp; console.log(Math.floor(7.8)); \/\/ Redondea al n\u00famero entero menor inmediato\n&nbsp; &nbsp; &nbsp; console.log(Math.round(7.8)); \/\/ Redondea al n\u00famero entero m\u00e1s cercano\n&nbsp; &nbsp; &nbsp; console.log(Math.round(7.2)); \/\/ Redondea al n\u00famero entero m\u00e1s cercano\n&nbsp; &nbsp; &nbsp; console.log(Math.sqrt(2)); \/\/ Ra\u00edz cuadrada\n&nbsp; &nbsp; &nbsp; console.log(Math.pow(2, 5)); \/\/ Potencia de un n\u00famero, el primer n\u00famero la base, el segundo el exponente\n&nbsp; &nbsp; &nbsp; console.log(Math.sign(-7.8)); \/\/ Indicador de si el n\u00famero es negativo (-), cero (0) o positivo (1)\n&nbsp; &nbsp; &nbsp; console.log(Math.random()); \/\/ Valor aleatorio comprendido entre 0 y 1\n&nbsp; &nbsp; &nbsp; console.log(Math.round(Math.random() * 1000)); \/\/ N\u00famero aleatorio entre 1 y 1000\n&nbsp; &nbsp; &lt;\/script&gt;\n&nbsp; &lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>El objeto Math nos ayuda mucho sobre todo si tenemos que hacer algunas operaciones matem\u00e1ticas especiales, se trata del objeto Math. Se trata de un objeto est\u00e1tico, hay que invocar directamente al prototipo. Veamos un ejm.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":697,"menu_order":2,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"class_list":["post-706","page","type-page","status-publish","hentry"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Sutil Web","author_link":"https:\/\/sutilweb.eu\/index.php\/author\/sutilweb\/"},"uagb_comment_info":0,"uagb_excerpt":"El objeto Math nos ayuda mucho sobre todo si tenemos que hacer algunas operaciones matem\u00e1ticas especiales, se trata del objeto Math. Se trata de un objeto est\u00e1tico, hay que invocar directamente al prototipo. Veamos un ejm.","_links":{"self":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/comments?post=706"}],"version-history":[{"count":2,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/706\/revisions"}],"predecessor-version":[{"id":708,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/706\/revisions\/708"}],"up":[{"embeddable":true,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/697"}],"wp:attachment":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/media?parent=706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}