"use strict";(self.webpackChunkdoris_website=self.webpackChunkdoris_website||[]).push([["26568"],{339638:function(e,n,t){t.r(n),t.d(n,{metadata:()=>c,contentTitle:()=>l,default:()=>u,assets:()=>o,toc:()=>a,frontMatter:()=>i});var c=JSON.parse('{"id":"sql-manual/sql-functions/numeric-functions/truncate","title":"TRUNCATE","description":"\x3c!--","source":"@site/versioned_docs/version-2.0/sql-manual/sql-functions/numeric-functions/truncate.md","sourceDirName":"sql-manual/sql-functions/numeric-functions","slug":"/sql-manual/sql-functions/numeric-functions/truncate","permalink":"/docs/2.0/sql-manual/sql-functions/numeric-functions/truncate","draft":false,"unlisted":false,"tags":[],"version":"2.0","frontMatter":{"title":"TRUNCATE","language":"en"},"sidebar":"docs","previous":{"title":"ROUND_BANKERS","permalink":"/docs/2.0/sql-manual/sql-functions/numeric-functions/round-bankers"},"next":{"title":"ABS","permalink":"/docs/2.0/sql-manual/sql-functions/numeric-functions/abs"}}'),r=t("785893"),s=t("250065");let i={title:"TRUNCATE",language:"en"},l=void 0,o={},a=[{value:"truncate",id:"truncate",level:2},{value:"description",id:"description",level:3},{value:"Syntax",id:"syntax",level:4},{value:"example",id:"example",level:3},{value:"keywords",id:"keywords",level:3}];function d(e){let n={code:"code",h2:"h2",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,s.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.h2,{id:"truncate",children:"truncate"}),"\n",(0,r.jsx)(n.h3,{id:"description",children:"description"}),"\n",(0,r.jsx)(n.h4,{id:"syntax",children:"Syntax"}),"\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.code,{children:"DOUBLE truncate(DOUBLE x, INT d)"}),"\nNumerically truncate ",(0,r.jsx)(n.code,{children:"x"})," according to the number of decimal places ",(0,r.jsx)(n.code,{children:"d"}),"."]}),"\n",(0,r.jsxs)(n.p,{children:["The rules are as follows:\nWhen ",(0,r.jsx)(n.code,{children:"d > 0"}),": keep ",(0,r.jsx)(n.code,{children:"d"})," decimal places of ",(0,r.jsx)(n.code,{children:"x"}),"\nWhen ",(0,r.jsx)(n.code,{children:"d = 0"}),": remove the fractional part of ",(0,r.jsx)(n.code,{children:"x"})," and keep only the integer part\nWhen ",(0,r.jsx)(n.code,{children:"d < 0"}),": Remove the fractional part of ",(0,r.jsx)(n.code,{children:"x"}),", and replace the integer part with the number ",(0,r.jsx)(n.code,{children:"0"})," according to the number of digits specified by ",(0,r.jsx)(n.code,{children:"d"})]}),"\n",(0,r.jsx)(n.h3,{id:"example",children:"example"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{children:"mysql> select truncate(124.3867, 2);\n+-----------------------+\n| truncate(124.3867, 2) |\n+-----------------------+\n|                124.38 |\n+-----------------------+\nmysql> select truncate(124.3867, 0);\n+-----------------------+\n| truncate(124.3867, 0) |\n+-----------------------+\n|                   124 |\n+-----------------------+\nmysql> select truncate(-124.3867, -2);\n+-------------------------+\n| truncate(-124.3867, -2) |\n+-------------------------+\n|                    -100 |\n+-------------------------+\n"})}),"\n",(0,r.jsx)(n.h3,{id:"keywords",children:"keywords"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{children:"TRUNCATE\n"})})]})}function u(e={}){let{wrapper:n}={...(0,s.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(d,{...e})}):d(e)}},250065:function(e,n,t){t.d(n,{Z:function(){return l},a:function(){return i}});var c=t(667294);let r={},s=c.createContext(r);function i(e){let n=c.useContext(s);return c.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),c.createElement(s.Provider,{value:n},e.children)}}}]);