LESSON 11 OF 52 · CHAPTER 01

Scalar Conversions

Explicit numeric conversion

ORIGINAL SOURCE

11-scalar-conversions.srp

bind count: integer = 42;
bind scaled: float = to_float(count) / 4.0;
bind exact: integer = to_integer(12.0);
print(scaled, exact, to_integer(-0.0));
EXPECTED OUTPUT

stdout

Verified
10.5 12 0

UNDERSTAND THE CODE

Explanation & practice

What this example teaches

Explicit numeric conversion

Expected behavior

10.5 12 0

Practice: Read the source before looking at the output. Predict the values and their order, then use the pinned compiler to execute this lesson and compare the exact fixture. Identify which operation produces the result.

संख्या के प्रकार बदलना

integer और float के बीच स्पष्ट रूपांतरण के लिए to_float और to_integer फ़ंक्शन प्रयोग होते हैं।

अभ्यास: 42 को float में बदलकर 4.0 से भाग देने का परिणाम निकालें।

Explanations are sourced from the project's English chapter guide and हिन्दी अध्याय. The Scarp program and output are unchanged.

TRY IT LOCALLY

Verify, then execute

Use the pinned compiler from the course root. Keep any imported _support files next to the source.

scarp verify examples/01-basics/11-scalar-conversions.srp scarp exec examples/01-basics/11-scalar-conversions.srp

The website does not run code. Read the CLI guide ↗

Pinned compiler: Scarp v0.0.6-alpha.3 · ceff07d9014f. No simulated output.