Skip to content

Commit

Permalink
Added vice versa functionality in String To Integer Calculator (#1756)
Browse files Browse the repository at this point in the history
  • Loading branch information
anijit18 authored Aug 3, 2024
1 parent b01bd8e commit 9c289dd
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 62 deletions.
15 changes: 15 additions & 0 deletions Calculators/Decimal-String-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# <p align="center">Decimal String Calculator</p>

## Description :-

This project is a simple web-based calculator that converts strings to integers or decimal numbers and vice-versa.

## Tech Stacks :-

- HTML
- CSS
- JavaScript

## Screenshots :-

![image](https://github.com/user-attachments/assets/68aa70ad-a6c9-45dc-b57f-e357c879192c)
34 changes: 34 additions & 0 deletions Calculators/Decimal-String-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Decimal String Calculator</title>
</head>

<body>
<div style="display:flex; gap:10px">
<div class="converter">
<h2>String To Decimal Calculator</h2>
<textarea id="inputString" placeholder="Enter your string here..."></textarea>
<br>
<button onclick="convertString()">Convert</button>
<br>
<div id="result1"></div>
</div>
<div class="converter">
<h2>Decimal To String Calculator</h2>
<textarea id="asciiInput" placeholder="Enter your integer separated by comma here..."></textarea>
<br>
<button onclick="convertAsciiToString()">Convert</button>
<br>
<div id="result2"></div>
</div>
</div>

<script src="script.js"></script>
</body>

</html>
24 changes: 24 additions & 0 deletions Calculators/Decimal-String-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function convertString() {
// Get the input string from the textarea
var inputString = document.getElementById('inputString').value;

// Convert each character to its ASCII value and join with spaces
var asciiValues = Array.from(inputString).map(char => char.charCodeAt(0)).join(' ');

// Display the result in the result div
document.getElementById('result1').textContent = asciiValues;
}

function convertAsciiToString() {
// Get the input value
let input = document.getElementById('asciiInput').value;

// Split the input string into an array of ASCII values
let asciiValues = input.split(',').map(value => parseInt(value.trim()));

// Convert ASCII values to characters and join them into a string
let result = asciiValues.map(value => String.fromCharCode(value)).join('');

// Display the result
document.getElementById('result2').textContent = result;
}
15 changes: 0 additions & 15 deletions Calculators/String-To-Integer-Calculator/README.md

This file was deleted.

23 changes: 0 additions & 23 deletions Calculators/String-To-Integer-Calculator/index.html

This file was deleted.

10 changes: 0 additions & 10 deletions Calculators/String-To-Integer-Calculator/script.js

This file was deleted.

28 changes: 14 additions & 14 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,20 @@ <h3>Effortlessly plan and manage your debt repayment with our easy-to-use Debt P
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Decimal String Calculator</h2>
<h3>Converts strings to decimal numbers and vice-versa.</h3>
<div class="card-footer">
<a href="./Calculators/Decimal-String-Calculator/index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Decimal-String-Calculator" title="Source Code" target="_blank">
<img src="./assets/images/github.png" alt="Source Code"></img>
</a>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Definite Integral Calculator</h2>
Expand Down Expand Up @@ -4523,20 +4537,6 @@ <h3>Validates the string patterns with various brackets to ensure every opening
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>String To Integer Calculator</h2>
<h3>Converts the provided string to integer or decimal value.</h3>
<div class="card-footer">
<a href="./Calculators/String-To-Integer-Calculator/index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/String-To-Integer-Calculator" title="Source Code" target="_blank">
<img src="./assets/images/github.png" alt="Source Code"></img>
</a>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Strong Number Calculator</h2>
Expand Down

0 comments on commit 9c289dd

Please sign in to comment.