ForHosting KIT · Math

Rectangle calculator

A rectangle 5 long and 3 wide has an area of 15 and a perimeter of 16. Enter the two sides once and read both figures in your own unit, squared for the area, so carpet and baseboard come from the same measurements. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Length
5
Width
3
You get
Area
15
Perimeter
16

The rectangle calculator computes the two numbers everyone needs from a rectangle: its area and its perimeter. There is no unit conversion, no guessing, and no ambiguity: whatever unit you measure in is the unit the answers come back in, squared for the area. Both dimensions must be positive finite numbers; anything else is rejected with a clear error before any computation happens.

What area and perimeter actually tell you

Area and perimeter answer two different questions about the same shape, and mixing them up is one of the most common measurement mistakes. The area tells you how much surface the rectangle covers — how much carpet a room needs, how much paintable wall you have, how much fabric a panel consumes. It grows with the product of the two sides, so doubling both sides quadruples it.

The perimeter tells you how long the boundary is — how much baseboard, fence, trim or edging you need to go all the way around. It only adds the sides together, so doubling both sides merely doubles it. A long thin strip and a compact square can share the same area while needing wildly different amounts of border material, which is why buying supplies from area alone so often comes up short.

Getting both numbers at once, from the same two measurements, is the point of this calculator: you enter the length and width once and read off whichever figure the job actually needs, in the units you measured in.

How the computation works

The math is the schoolbook formula, applied exactly: the area is the length multiplied by the width, and the perimeter is twice the sum of the two. Both dimensions are validated before anything is computed — each must be a positive finite number, which means zero, negative values, empty input, text that is not a number, and infinities are all rejected with a descriptive error instead of producing a silent wrong answer. Numeric strings like "2.5" are accepted and converted, because real-world measurements often arrive as text.

There is no randomness, no clock, and no network call anywhere in the computation: the same two inputs always produce the same two outputs, which is what makes the result safe to cache, audit and quote in a document.

When you need both figures at once

A mobile app can offload the check so a user typing "abc" into the width field gets a clean error rather than a NaN propagated into an invoice. Batch jobs that normalize measurement spreadsheets can stream rows through it and rely on the rejection of non-positive values as a data-quality gate. Because the capability is deterministic and stateless, results are trivially cacheable and testable: your integration tests can assert exact outputs.

And because the same code runs free on this page, the person writing the specification can verify by hand exactly what the paid pipeline will compute — no drift between the documentation, the demo and production behavior.

Quote flooring and fencing from room dimensions

Feed length and width per room and get the square meters of material plus the linear meters of skirting in one call per room.

What inputs does it accept?

A length and a width, each a positive finite number.

What units does it use?

Whatever units you send. If length and width are in meters, the perimeter comes back in meters and the area in square meters.

What formulas does it apply?

Results are rounded to six decimal places for stable, reproducible output.

Does it compute the diagonal or anything else?

No. It returns exactly the area and the perimeter. For the diagonal, use the dedicated rectangle diagonal capability.

Is the result deterministic?

Yes. There is no randomness, clock or network in the computation — the same inputs always produce byte-for-byte identical outputs.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/math/generic-rectangle

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/math/generic-rectangle \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"length":5,"width":3}'
{
  "length": 5,
  "width": 3
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "math.generic_rectangle",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

You send the length and the width — in any unit, as plain numbers — and you get both results back in one call, computed with the exact formulas area = length × width and perimeter = 2 × (length + width). It runs free in your browser on this page, and the same deterministic code answers API requests for $0.002 per call, so the result you see here is exactly the result your application will get.

How the computation works

Results are rounded to six decimal places, which is far beyond any practical measurement precision and keeps the output stable across machines and languages, so an answer computed in your browser is byte-for-byte identical to the one the API returns.

Where a rectangle API earns its place

Nobody needs an API to multiply two numbers once — the value appears when the calculation is embedded in a system that runs it a thousand times. A quoting engine that prices flooring, fencing, glass or printing by dimensions can call this endpoint per line item and get consistent, validated numbers instead of re-implementing validation in every service.

Validate dimensions in a quoting pipeline

Reject zero, negative or non-numeric measurements at the edge with a clear invalid_input error instead of letting a NaN reach an invoice.

Normalize measurement spreadsheets in bulk

Stream rows of length/width pairs through the API and use the deterministic output as an auditable, cacheable result.

What does it cost?

$0.002 per request via the API. It is also free to run in your browser on this page, with the exact same code.

Read the full KIT documentation →