Skip to main content

A lightweight Python library for calculating GPA, CGPA, and SGPA. Supports 4.0 and 5.0 grading scales.

Project description

CGPA Calculator

A lightweight JavaScript library for calculating GPA (Grade Point Average), CGPA (Cumulative GPA), and SGPA (Semester GPA).

Try the online version at gpacalc.app

Installation

npm install cgpa-calculator

Quick Start

const { calculateGPA, calculateCGPA, gpaToLetter } = require('cgpa-calculator');

// Calculate semester GPA
const gpa = calculateGPA([
  { grade: 'A', credits: 4 },
  { grade: 'B+', credits: 3 },
  { grade: 'A-', credits: 3 },
  { grade: 'B', credits: 2 }
]);

console.log(gpa); // 3.58
console.log(gpaToLetter(gpa)); // 'B+'

API

calculateGPA(courses, options?)

Calculate GPA from a list of courses.

const gpa = calculateGPA([
  { grade: 'A', credits: 3 },
  { grade: 'B', credits: 4 }
], { scale: '4.0' });

Parameters:

  • courses - Array of { grade: string | number, credits: number }
  • options.scale - Grading scale: '4.0' (default) or '5.0'

calculateCGPA(semesters, options?)

Calculate cumulative GPA across multiple semesters.

const cgpa = calculateCGPA([
  [{ grade: 'A', credits: 3 }, { grade: 'B', credits: 4 }],
  [{ grade: 'A-', credits: 3 }, { grade: 'B+', credits: 3 }]
]);

calculateSGPA(courses, options?)

Alias for calculateGPA. Calculate a single semester's GPA.

percentageToGPA(percentage, scale)

Convert percentage score to GPA.

percentageToGPA(85, '4.0'); // 3.5
percentageToGPA(92, '5.0'); // 5.0

gpaToLetter(gpa)

Convert numeric GPA to letter grade.

gpaToLetter(3.5); // 'B+'
gpaToLetter(4.0); // 'A'

getGradePoint(grade, scale)

Get the numeric value for a letter grade.

getGradePoint('A', '4.0'); // 4.0
getGradePoint('B+', '5.0'); // 4.0

Supported Grade Scales

4.0 Scale

Grade Points
A+/A 4.0
A- 3.7
B+ 3.3
B 3.0
B- 2.7
C+ 2.3
C 2.0
C- 1.7
D+ 1.3
D 1.0
F 0.0

5.0 Scale

Grade Points
A+/A 5.0
A- 4.5
B+ 4.0
B 3.5
C+ 2.5
C 2.0
D 1.0
F 0.0

Online Calculator

For a visual, interactive GPA calculator, visit gpacalc.app.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cgpa_calc-1.0.0.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cgpa_calc-1.0.0-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file cgpa_calc-1.0.0.tar.gz.

File metadata

  • Download URL: cgpa_calc-1.0.0.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for cgpa_calc-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9113a5f8be9275820773c33ee9dcdb5986f47e4c5ddf08c35e03a74bdea0ecbf
MD5 9bb59b09cc42d377d2f72ac5e5bb2877
BLAKE2b-256 8f9d8bbc13e42ee3fb5c26cb4bb5960f88f5ebd71261f19f8153b4f16fe4b137

See more details on using hashes here.

File details

Details for the file cgpa_calc-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: cgpa_calc-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for cgpa_calc-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f90988e1f7c470f1912b1b3e657242d985216d32524193ff05bb6bbab5361ed3
MD5 1f65fdc2bf430a54ec6c850f3af6fda5
BLAKE2b-256 e4d65ff118ce410d11a49a5efe29b13df65d7cfe4ea1a7d38b64c8abeefc9353

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page