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.

Related Resources

GPA Calculator -- Free online GPA, CGPA, and SGPA calculator for students worldwide.

Also available for:

Learn more:

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.1.tar.gz (3.5 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.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cgpa_calc-1.0.1.tar.gz
  • Upload date:
  • Size: 3.5 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.1.tar.gz
Algorithm Hash digest
SHA256 a3cffbdc4de62596f3e040a63ab0aa4f781d4aa1ede09c6200eb51c70caa7015
MD5 80f00f8edb2f91ad6254aa53ccb0e16b
BLAKE2b-256 0fb6f4d76d2db6b0fb4528a5eec128a433097fbd7fdaded634d1d227841342db

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cgpa_calc-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.5 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8e2323290958272404a28325b509dd988dbdbca9a15f1a15557e05dc45ad96a6
MD5 b7eacc489fb7f300484dab75e06d70f5
BLAKE2b-256 3c158e5df181afd8790bcf51b03eac73316dbf1a4f92be527f54994409086861

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