Skip to content
EspañolWorkspace →

PSeInt Trunc: keep the whole part of a number

Cuts off the decimal part and keeps the whole part, without rounding.

Template
Trunc
Open it in Codoritmo

Opens the editor with this example loaded. Run it step by step and watch the flowchart.

Worked example

A complete algorithm, ready to copy and run.

trunc-truncate.psc · 3 lines
Algoritmo Example    Escribir Trunc(7.9)FinAlgoritmo

Output

Shows: 7 (it doesn't round up to 8)

This is what the console shows when the example runs.

7

In a flowchart

This is how it appears in a flowchart, with the same shapes Codoritmo draws.

enteros ← Trunc(x)
Used inside a calculation. It has no shape of its own; it's used inside a calculation. Flowchart: a process rectangle reading "enteros ← Trunc(x)", with one arrow in and one arrow out.
Draw the flowchart of your own algorithm →

Template

The general form. Replace what's inside < > with your own data.

Trunc · 1 line
Trunc(<numero>)

Examples that use it

Programs from the example library where it appears, from the simplest to the most complete.

  • Parking Fee

    Charges every started hour, with a daily maximum.

    Intermediate
  • Binary Search

    Finds a value in a sorted array by halving the range every step.

    Intermediate
  • Linear vs. Binary Search

    Counts the comparisons each search needs on the same sorted list.

    Intermediate
  • GCD and LCM

    Computes the greatest common divisor and the least common multiple.

    Intermediate
  • Shell Sort

    Insertion sort between far-apart elements, with a gap that shrinks every pass.

    Advanced
  • Merge Sort

    Splits the array in halves, sorts each one recursively and merges them.

    Advanced
See every Math example →

More math functions

Codoritmo is an independent, open-source project inspired by PSeInt and compatible with its syntax. It is not affiliated with the PSeInt project. Official PSeInt website.